Upload Media 1.1

javascript

#1

Hello trying to upload we get {“code”:38,“message”:“media parameter is missing.”}
Here is the code

 uploadimage: function (img, callback) {
        var fs = require('fs');
        var b64content = fs.readFileSync('img/farobot4.png', { encoding: 'base64' })
        var request_options = {
            url: 'https://upload.twitter.com/1.1/media/upload.json',
            oauth: twitter_oauth,
            //json: true,
            headers: {
                'content-type': 'application/x-www-form-urlencoded',
            },
        }
        request.post(request_options, function (error, response, body) {

        if (error) {
           
            console.log(error)
            return
        }
        callback(null, { 'base64': body });
    })

#2

I don’t see a media parameter in your call to the endpoint?

I don’t have a Javascript example handy, but you may find the large media upload sample in Python useful.


#3

Sorry
var request_options = {
url: ‘https://upload.twitter.com/1.1/media/upload.json’,
oauth: twitter_oauth,
//json: true,
headers: {
‘content-type’: ‘application/x-www-form-urlencoded’,
},
media:b64content;
}


#4

Andy I would like to use this simple POST for uploading images.
Yours Pedro


#5

This a new code
uploadimage: function (img, callback) {
var fs = require(‘fs’);
var b64content = fs.readFileSync(‘img/farobot4.gif’, { encoding: ‘base64’ })

    var request_options = {
        url: 'https://upload.twitter.com/1.1/media/upload.json',
        oauth: twitter_oauth,
        //json: true,
        headers: {
           // 'content-type': 'application/x-www-form-urlencoded',
            'content-type':'multipart/form-data'
           // 'Content-Transfer-Encoding': 'base64'
        },
        //'media': b64content,
           // 'media_data': b64content

        media_data: b64content
    }
    request.post(request_options, function (error, response, body) {

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

An I get the following error:
{“errors”:[{“code”:214,“message”:“Bad request.”}]