Media upload fails if charset is specified



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...


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?


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
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:


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


I am having the same problem. Can you share de code?

uploadimage: function (img, callback) {
        var fs = require('fs');
        var b64content = fs.readFileSync('img/farobot4.gif', { encoding: 'base64' })
        var request_options = {
            url: '',
            oauth: twitter_oauth,
            media_data: b64content,
            json: true,
            headers: {
               // 'content-type': 'application/x-www-form-urlencoded',
               // 'Content-Transfer-Encoding': 'base64'
        }, function (error, response, body) {

        if (error) {
            console.log('Error creating welcome message.')
        callback(null, { 'base64': body });