Hi,
I have a problem with the API and following HTTP-request (PHP-Code):
$message = "--".$boundary." Content-Type: application/x-www-form-urlencoded
ignorewarnings=1&token=".urlencode($token)."&filename=".urlencode($new_file) ."&file=".urlencode("file")."&comment=".urlencode($desc)."
--".$boundary." Content-Type: application/octet-stream Content-Disposition: form-data; name="file"; filename="".$new_file.""
".$file." --".$boundary."--";
$query = "POST ".$this->server_dir."/api.php?format=php&action=upload HTTP/1.1 Host: ".$this->server." Cookie: ".$this->cookies." User-Agent: CommonsHelper2/1.0 Beta (http://toolserver.org/~commonshelper2/index.php jan@toolserver.org) Content-Type: multipart/form-data; boundary=".$boundary." Content-Length: ".strlen($message)."
".$message." \r\n\r\n";
$token is the edit token, $boundary a prefix with the output of time(), $this->server_dir is "/w", $this->server is "commons.wikimedia.org"
But when I do this request I get this error (var_dump): array(1) { ["error"]=> array(2) { ["code"]=> string(7) "notoken" ["info"]=> string(31) "The token parameter must be set" } }
Can you help me?
Best regards, Jan
On Sat, Jan 1, 2011 at 6:13 PM, Jan Luca jan@jans-seite.de wrote:
Hi,
I have a problem with the API and following HTTP-request (PHP-Code):
$message = "--".$boundary." Content-Type: application/x-www-form-urlencoded
ignorewarnings=1&token=".urlencode($token)."&filename=".urlencode($new_file) ."&file=".urlencode("file")."&comment=".urlencode($desc)."
--".$boundary." Content-Type: application/octet-stream Content-Disposition: form-data; name="file"; filename="".$new_file.""
".$file." --".$boundary."--";
I have never tried mixing x-www-form-urlencoded with multipart/form-data. Try encoding each field as their own part in the multipart blob.
Another tip, always sent the edit token as the last field. If you send the edit token before the file and your upload gets interrupted half way, a half uploaded file will appear. PHP does not care about your Content-Length header...
Bryan
mediawiki-api@lists.wikimedia.org