Media_data/upload returns Status Code 400

api

#1

I am trying to upload an image to twitter account using twitter’s media upload api. I am using node-twitter module for nodejs.

This is the code i am using

`var base64Image = data.image;
client.post(‘media/upload’, { media_data: base64Image }, function (error, media_data, response) {
if (!error) {
// If successful, a media object will be returned.
console.log(media_data);

                // Lets tweet it
                var status = {
                    status: 'Sample tweet'+ randomHashtag,
                    media_ids: media_data.media_id_string // Pass the media id string
                }                

                client.post('statuses/update', status, function (error, tweet, response) {
                    if (!error) {
                        console.log(tweet);
                    }
                });

            }
            else {
                console.log(error);
            }
        });`

I have also tried these errors but its not working

app.use(function (req, res, next) { res.setHeader('Content-Type', 'multipart/form-data'); res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Transfer-Encoding',' base64'); next(); } );