Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Wikitech

Problem with Upload API

 

 

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded


jan at jans-seite

Oct 21, 2009, 3:15 AM

Post #1 of 11 (1380 views)
Permalink
Problem with Upload API

Hi,

I want to use the new Upload-API. I have seen that I cannot upload per URL
to Commons because I (my bot) haven't the
upload_by_url right. So I change my tool to the file argument:

$new_file = <Name of the target file>;
$url = <URL of the source file>;
$desc = <Description>;
$filename = <Name of the source file>;
$this->server = 'commons.wikimedia.org';

$connect = fsockopen ($this->server, 80, $err_num, $err_str, 10);

$token = $this->get_token();

$file = file_get_contents( $url );
$query = "POST
/w/api.php?format=php&action=upload&filename=".urlencode($new_file)."&token=
".urlencode($token)."&file=".urlencode($filename)."&comment=".urlencode($des
c)." HTTP/1.1
Host: ".$this->server."
Cookie: ".$cookies."
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7)
Gecko/20041107 Firefox/1.0
Content-Type: multipart/form-data
Content-Length: ".strlen($file)."
Content-Disposition: form-data; name=\"".$filename."\";
filename=\"".$filename."\"

".$file."
\r\n\r\n";
fputs ($connect,$query);

But now I get this error: array(1) { ["error"]=> array(2) { ["code"]=>
string(12) "missingparam" ["info"]=> string(69) "One of the parameters
sessionkey, file, url, enablechunks is required" } }

What is wrong?

Viele Grüße
Jan


_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


bryan.tongminh at gmail

Oct 21, 2009, 3:24 AM

Post #2 of 11 (1313 views)
Permalink
Re: Problem with Upload API [In reply to]

On Wed, Oct 21, 2009 at 12:15 PM, Jan Luca <jan [at] jans-seite> wrote:
[...]
> Content-Type: multipart/form-data
> Content-Length: ".strlen($file)."
> Content-Disposition: form-data; name=\"".$filename."\";
> filename=\"".$filename."\"
>
> ".$file."
> \r\n\r\n";

You do set your content-type to multipart/form-data, but your content
is not actually multipart/form-data encoded. A multipart/form-data
encoded request looks something like this:

POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=abc
Content-Length: 1234

--abc
Content-Disposition: form-data; name="%s"; filename="%s"
Content-Type: application/octet-stream

<FILECONTENT>
--abc
Content-Disposition: form-data; name="%s"

data
--abc
Content-Disposition: form-data; name="%s"

data
--abc--


Bryan

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


agarrett at wikimedia

Oct 21, 2009, 3:35 AM

Post #3 of 11 (1304 views)
Permalink
Re: Problem with Upload API [In reply to]

On 21/10/2009, at 11:15 AM, Jan Luca wrote:

> Hi,
>
> I want to use the new Upload-API. I have seen that I cannot upload
> per URL
> to Commons because I (my bot) haven't the
> upload_by_url right. So I change my tool to the file argument:

Why are you building an HTTP request by yourself? Use a library to do
the HTTP request and you will save yourself a lot of problems.

--
Andrew Garrett
agarrett [at] wikimedia
http://werdn.us/


_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


jan at jans-seite

Oct 21, 2009, 3:37 AM

Post #4 of 11 (1304 views)
Permalink
Re: Problem with Upload API [In reply to]

Hi,

is "Content-Length:" the other header, too`

Other header e.g:

--abc
Content-Disposition: form-data; name="%s"; filename="%s"
Content-Type: application/octet-stream

Viele Grüße
Jan

-----Ursprüngliche Nachricht-----
Von: wikitech-l-bounces [at] lists
[mailto:wikitech-l-bounces [at] lists] Im Auftrag von Bryan Tong
Minh
Gesendet: Mittwoch, 21. Oktober 2009 12:25
An: Wikimedia developers
Betreff: Re: [Wikitech-l] Problem with Upload API

On Wed, Oct 21, 2009 at 12:15 PM, Jan Luca <jan [at] jans-seite> wrote:
[...]
> Content-Type: multipart/form-data
> Content-Length: ".strlen($file)."
> Content-Disposition: form-data; name=\"".$filename."\";
> filename=\"".$filename."\"
>
> ".$file."
> \r\n\r\n";

You do set your content-type to multipart/form-data, but your content
is not actually multipart/form-data encoded. A multipart/form-data
encoded request looks something like this:

POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=abc


--abc
Content-Disposition: form-data; name="%s"; filename="%s"
Content-Type: application/octet-stream

<FILECONTENT>
--abc
Content-Disposition: form-data; name="%s"

data
--abc
Content-Disposition: form-data; name="%s"

data
--abc--


Bryan

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


bryan.tongminh at gmail

Oct 21, 2009, 4:04 AM

Post #5 of 11 (1324 views)
Permalink
Re: Problem with Upload API [In reply to]

Hi,

On Wed, Oct 21, 2009 at 12:37 PM, Jan Luca <jan [at] jans-seite> wrote:
> is "Content-Length:" the other header, too`
>

It is in my experience and as far as I am aware not necessary. Please
see RFC2388 [1] for more information. What usually also helps is
sniffing your browser traffic (Firebug under firefox).


Bryan


[1] http://www.faqs.org/rfcs/rfc2388.html

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


russblau at hotmail

Oct 21, 2009, 7:29 AM

Post #6 of 11 (1309 views)
Permalink
Re: Problem with Upload API [In reply to]

"Bryan Tong Minh" <bryan.tongminh [at] gmail> wrote in message
news:fd5886130910210324l409d2cc6m31831366ae4bb737 [at] mail
> On Wed, Oct 21, 2009 at 12:15 PM, Jan Luca <jan [at] jans-seite> wrote:
> [...]
>> Content-Type: multipart/form-data
>> Content-Length: ".strlen($file)."
>> Content-Disposition: form-data; name=\"".$filename."\";
>> filename=\"".$filename."\"
>>
>> ".$file."
>> \r\n\r\n";
>
> You do set your content-type to multipart/form-data, but your content
> is not actually multipart/form-data encoded. A multipart/form-data
> encoded request looks something like this:
>
> POST / HTTP/1.1
> Content-Type: multipart/form-data; boundary=abc
> Content-Length: 1234
>
> --abc
> Content-Disposition: form-data; name="%s"; filename="%s"
> Content-Type: application/octet-stream
>
> <FILECONTENT>
> --abc

What is the second "%s" in the above line? Is this instead of having a
separate form-data element with name="filename", or is it a duplicate of
that element, or is it something entirely different?

I note that RFC 2388 says: "The original local file name may be supplied as
well, either as a "filename" parameter either of the "content-disposition:
form-data" header or, in the case of multiple files, in a
"content-disposition: file" header of the subpart. The sending application
MAY supply a file name; if the file name of the sender's operating system is
not in US-ASCII, the file name might be approximated, or encoded using the
method of RFC 2231."

If RFC 2388 says that the sending application MAY supply a file name, why is
the API treating this as a REQUIRED parameter?

Russ





_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


bryan.tongminh at gmail

Oct 21, 2009, 7:55 AM

Post #7 of 11 (1308 views)
Permalink
Re: Problem with Upload API [In reply to]

On Wed, Oct 21, 2009 at 4:29 PM, Russell Blau <russblau [at] hotmail> wrote:
>> --abc
>> Content-Disposition: form-data; name="%s"; filename="%s"
>> Content-Type: application/octet-stream
>>
> What is the second "%s" in the above line?  Is this instead of having a
> separate form-data element with name="filename", or is it a duplicate of
> that element, or is it something entirely different?
>
name is the name of the form element (wpUploadFile) and filename the
name of the file (picture.jpg)

> If RFC 2388 says that the sending application MAY supply a file name, why is
> the API treating this as a REQUIRED parameter?
It is not, as far as I can see. It is requiring the form element
"filename" and ignoring the filename attribute from the file all
together.


Bryan

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


bryan.tongminh at gmail

Oct 21, 2009, 7:56 AM

Post #8 of 11 (1307 views)
Permalink
Re: Problem with Upload API [In reply to]

On Wed, Oct 21, 2009 at 4:55 PM, Bryan Tong Minh
<bryan.tongminh [at] gmail> wrote:
> name is the name of the form element (wpUploadFile) and filename the
> name of the file (picture.jpg)
(In case of the api wpUploadFile is simply "file"; wpUploadFile is for
the regular upload form)

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


russblau at hotmail

Oct 21, 2009, 8:18 AM

Post #9 of 11 (1302 views)
Permalink
Re: Problem with Upload API [In reply to]

[.adding mediawiki-api since this seems to be more relevant to that list]

"Bryan Tong Minh" <bryan.tongminh [at] gmail> wrote:
>On Wed, Oct 21, 2009 at 4:29 PM, Russell Blau <russblau [at] hotmail> wrote:
>>> --abc
>>> Content-Disposition: form-data; name="%s"; filename="%s"
>>> Content-Type: application/octet-stream
>>>
>> What is the second "%s" in the above line? Is this instead of having a
>> separate form-data element with name="filename", or is it a duplicate of
>> that element, or is it something entirely different?
>>
>name is the name of the form element (wpUploadFile) and filename the
>name of the file (picture.jpg)
>
>> If RFC 2388 says that the sending application MAY supply a file name, why
>> is
>> the API treating this as a REQUIRED parameter?
>It is not, as far as I can see. It is requiring the form element
>"filename" and ignoring the filename attribute from the file all
>together.

So, basically, the API for action=upload is (a) not compliant with RFC 2388,
and (b) failing with a misleading error message when the client fails to
supply a parameter that isn't used at all?

Russ




_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


jan at jans-seite

Oct 21, 2009, 8:24 AM

Post #10 of 11 (1303 views)
Permalink
Re: Problem with Upload API [In reply to]

Hello,

thank you for you help! Now it works.

Viele Grüße
Jan

-----Ursprüngliche Nachricht-----
Von: wikitech-l-bounces [at] lists
[mailto:wikitech-l-bounces [at] lists] Im Auftrag von Bryan Tong
Minh
Gesendet: Mittwoch, 21. Oktober 2009 12:25
An: Wikimedia developers
Betreff: Re: [Wikitech-l] Problem with Upload API

On Wed, Oct 21, 2009 at 12:15 PM, Jan Luca <jan [at] jans-seite> wrote:
[...]
> Content-Type: multipart/form-data
> Content-Length: ".strlen($file)."
> Content-Disposition: form-data; name=\"".$filename."\";
> filename=\"".$filename."\"
>
> ".$file."
> \r\n\r\n";

You do set your content-type to multipart/form-data, but your content
is not actually multipart/form-data encoded. A multipart/form-data
encoded request looks something like this:

POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=abc
Content-Length: 1234

--abc
Content-Disposition: form-data; name="%s"; filename="%s"
Content-Type: application/octet-stream

<FILECONTENT>
--abc
Content-Disposition: form-data; name="%s"

data
--abc
Content-Disposition: form-data; name="%s"

data
--abc--


Bryan

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


roan.kattouw at gmail

Oct 21, 2009, 8:49 AM

Post #11 of 11 (1304 views)
Permalink
Re: Problem with Upload API [In reply to]

2009/10/21 Russell Blau <russblau [at] hotmail>:
> So, basically, the API for action=upload is (a) not compliant with RFC 2388,
> and (b) failing with a misleading error message when the client fails to
> supply a parameter that isn't used at all?
>
Neither of these is true. The filename parameter specifies the name of
the file ON THE WIKI, like the second textbox in Special:Upload does.

Roan Kattouw (Catrope)

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.