Hello,
I want to use in my tool the new "Upload API".
I call (after login):
$new_file = <Name of the target file>; $file = <URL of the source file>; $desc = <Description>; $this->server = 'commons.wikimedia.org'
$connect = fsockopen ($this->server, 80, $err_num, $err_str, 10); $token = $this->get_token(); //Works $message = "filename=".urlencode($new_file)."&token=".urlencode($token)."&url=".$file." &comment=".urlencode($desc); if( $connect ) { $query = "POST /w/api.php?format=php&action=upload 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: application/x-www-form-urlencoded Content-Length: ".strlen($message)."
".$message." \r\n\r\n"; fputs ($connect,$query);
The answer is: array(1) { ["upload"]=> array(1) { ["upload_session_key"]=> int(<ID, e.g. 2095449403>) } }
But the file isn't uploaded. What do I wrong?
Viele Grüße Jan
Hi,
On Mon, Oct 19, 2009 at 7:39 PM, Jan Luca jan@jans-seite.de wrote:
Content-Type: application/x-www-form-urlencoded Content-Length: ".strlen($message)."
File uploads should always be encoded in multipart/form-data format.
Regards, Bryan
On Mon, Oct 19, 2009 at 8:02 PM, Bryan Tong Minh bryan.tongminh@gmail.com wrote:
Hi,
On Mon, Oct 19, 2009 at 7:39 PM, Jan Luca jan@jans-seite.de wrote:
Content-Type: application/x-www-form-urlencoded Content-Length: ".strlen($message)."
File uploads should always be encoded in multipart/form-data format.
Ignore that, I see you are using upload by url. Somehow the async mode is triggered, but I don't see how. I will see when I can investigate this.
Bryan
Hi,
I have seen that I cannot upload per URL 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
-----Ursprüngliche Nachricht----- Von: mediawiki-api-bounces@lists.wikimedia.org [mailto:mediawiki-api-bounces@lists.wikimedia.org] Im Auftrag von Bryan Tong Minh Gesendet: Montag, 19. Oktober 2009 20:06 An: MediaWiki API announcements & discussion Betreff: Re: [Mediawiki-api] Problem with Upload API
On Mon, Oct 19, 2009 at 8:02 PM, Bryan Tong Minh bryan.tongminh@gmail.com wrote:
Hi,
On Mon, Oct 19, 2009 at 7:39 PM, Jan Luca jan@jans-seite.de wrote:
Content-Type: application/x-www-form-urlencoded Content-Length: ".strlen($message)."
File uploads should always be encoded in multipart/form-data format.
Ignore that, I see you are using upload by url. Somehow the async mode is triggered, but I don't see how. I will see when I can investigate this.
Bryan
_______________________________________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Resolved in wikitech-l!
-----Ursprüngliche Nachricht----- Von: mediawiki-api-bounces@lists.wikimedia.org [mailto:mediawiki-api-bounces@lists.wikimedia.org] Im Auftrag von Jan Luca Gesendet: Dienstag, 20. Oktober 2009 10:03 An: 'MediaWiki API announcements & discussion' Betreff: Re: [Mediawiki-api] Problem with Upload API
Hi,
I have seen that I cannot upload per URL 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
-----Ursprüngliche Nachricht----- Von: mediawiki-api-bounces@lists.wikimedia.org [mailto:mediawiki-api-bounces@lists.wikimedia.org] Im Auftrag von Bryan Tong Minh Gesendet: Montag, 19. Oktober 2009 20:06 An: MediaWiki API announcements & discussion Betreff: Re: [Mediawiki-api] Problem with Upload API
On Mon, Oct 19, 2009 at 8:02 PM, Bryan Tong Minh bryan.tongminh@gmail.com wrote:
Hi,
On Mon, Oct 19, 2009 at 7:39 PM, Jan Luca jan@jans-seite.de wrote:
Content-Type: application/x-www-form-urlencoded Content-Length: ".strlen($message)."
File uploads should always be encoded in multipart/form-data format.
Ignore that, I see you are using upload by url. Somehow the async mode is triggered, but I don't see how. I will see when I can investigate this.
Bryan
_______________________________________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
_______________________________________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
mediawiki-api@lists.wikimedia.org