Media upload fails if charset is specified

media-upload
api
bug

#1

Hi all!
I believe that there is a bug in how the server processes the media upload requests (both chunked and unchunked versions): it normally works, but if the application specifies a charset in the Content-Type header, then it fails with the usual error:

{"errors":[{"code":38,"message":"media parameter is missing."}]}

I’ve tried the upload many times, and I’ve verified that it fails whenever I change the header from

Content-Type: multipart/form-data, boundary=...blabla...

to

Content-Type: multipart/form-data, boundary=...blabla...;charset=UTF8

Unfortunately, the charset=UTF-8 part is automatically added by the XMLHttpRequest.send() method (at least, in its QML implementation), so I don’t have control over that. Can some twitter dev please double check this?


#2

After investigating the issue more, I realized that the reason why this failed is that I was using two different separators in the Content-Type line; and indeed, changing the header from
Content-Type: multipart/form-data, boundary=...blabla...;charset=UTF8
to
Content-Type: multipart/form-data; boundary=...blabla...;charset=UTF8
(note how the comma before boundary gets changed into a semicolon) was enough to make the upload succeed. :slight_smile:


#3

Great to hear you got it working, thanks for sharing the solution!