Hello everyone 
I’m trying to upload a canvas.toDataURL() to twitter account/update_profile_image with this codes:
[ javascript ]
var xhr = new XMLHttpRequest(),
fileUpload = xhr.upload,
boundary = 'multipartformboundary' + (new Date).getTime();
fileUpload.addEventListener("load", function(ajax){
console.debug(ajax); // getting the response
}, false);
xhr.open("POST", "uploadimage.php", true);
xhr.setRequestHeader('content-type', 'multipart/form-data; boundary='+ boundary);
builder = '--' + boundary + '\r\n Content-Disposition: form-data; name="image"; filename="upload.png"\r\n Content-Type: image/png \r\n\r\n';
builder += (canvas.toDataURL('image/png').split(","))[1];
builder += '\r\n--' + boundary + '--\r\n';
xhr.send(builder);
[ uploadimage.php ]
var_dump($_FILES);
if ( isset($_SESSION['access_token']) ) {
$tmhOAuth->config['user_token'] = $_SESSION['access_token']['oauth_token'];
$tmhOAuth->config['user_secret'] = $_SESSION['access_token']['oauth_token_secret'];
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1/account/verify_credentials'));
if ($code == 200) {
$R = json_decode($tmhOAuth->response['response']);
$params = array(
'image' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
);
$code = $tmhOAuth->request('POST', $tmhOAuth->url("1/account/update_profile_image"),
$params,
true, // use auth
true // multipart
);
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
}
tmhUtilities::pr(htmlentities($tmhOAuth->response['response']));
} else {
outputError($tmhOAuth);
}
}
So the var_dump($_FILES) throw this:
array(1) {
["image"]=>
array(5) {
["name"]=>
string(11) "upload.png"
["type"]=>
string(9) "image/png"
["tmp_name"]=>
string(14) "/tmp/phpMe8k3c"
["error"]=>
int(0)
["size"]=>
int(2432)
}
}
And I get this twitter response:
<pre style="word-wrap: break-word">{"error":"There was a problem with your picture. Probably too big.","request":"\/1\/account\/update_profile_image.json"}</pre>
What do you think is happening? I’m stuck in this…
My resources to the above codes are: