Sample multipart/form-data image request


#1

I’m looking for a sample working multipart/form-data request that uploads an image
https://upload.twitter.com/1.1/media/upload.json

I’ve tried everything to create the request per known specs and always get this error:
System.HttpResponse[Status=Internal Server Error, StatusCode=500]
|{“errors”:[{“message”:“Internal error”,“code”:131}]}

Does Twitter not accept a Content-Type of multipart/form-data?
req.setHeader(‘Content-Type’, ‘multipart/form-data; boundary=’+boundary)

I’m guessing this because even when I put in bogus oauth credentials, I get the same error.
If I change the Content-Type to something else, then I get a 401 authentication error.


#2

@MichaelLin7 https://dev.twitter.com/rest/public/uploading-media has few twurl command examples. You could add -t argument to get request and response trace logs. For example,

twurl -H upload.twitter.com -X POST “/1.1/media/upload.json” --file “/path/to/image.jpg” --file-field “media” -t

Upload api accepts multipart/form-data content type.


#3