I try to upload an image via Twitter api , as described there I created a form with name="status"
and name="media[]"
-
<form id="image-form">
<input type="text" name="status">
<input name="media[]" type="file" />
<input type="submit" value="POST IMAGE">
</form>
in addition I have a submit
handler -
$('#image-form').submit( function(e) {
e.preventDefault();
var formData = new FormData(this); // <-- 'this' is your form element
$.ajax({
url:'https://api.twitter.com/1.1/statuses/update_with_media.json',
type: 'POST',
contentType: false,
pagerocessData: false,
processData: false,
data: formData,
success: function(data) {
alert('Image upload succeeded');
},
error: function (responseData, textStatus, errorThrown) {
alert('GET failed.');
}
});
});
Under Networks at Chrome I see this request with Content-Type:multipart/form-data
finally I get "response 200" but it doesn't upload an image to the Twitter account ,
What I did wrong here ?
I couldn't post this as a comment, so I'm going to risk my life writing it as an answer :P.
I tried Exploring the Twitter API (on Firefox works, in Chrome it fails when loading it).
Steps to set up the testing
https://api.twitter.com/1.1
, it will show up some options. In the endpoints list select the one you are using.No auth
, Basic Auth
and none of them worked)status
- The tweet message.media
, select an image.Finally press send
.
What I can notice is that if I don't specify an image nor text it will fail (obviously). If I set an image without a status it will upload the image, and if I specify both, well... it will upload the image with the text.
Note that the status is appended to the URL.
So a few questions :
Here's the result of the fake account I made.
I hope at least it gives you a hint of what it can be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With