I am attempting to upload an image with nodejs, the response I am getting does not appear to be an authentication issue. The function I am calling on behalf of the logged in user, I have other functions that pulls user_timeline and functions as expected. “err” returns null (which is strange as normally it should be undefined) and “res” returns a large JSON object that I can not tell what the error is.
exports.twitter_image = function(message, file_path, accessKey, accessSecret, callback) {
var client = new Twitter({
consumer_key: TWITTER_CONSUMER_KEY,
consumer_secret: TWITTER_CONSUMER_SECRET,
access_token_key: accessKey,
access_token_secret: accessSecret
});
fs.readFile(file_path.fileName.path, {encoding: 'base64'}, function(err, imageB64) {
var form = new FormData();
form.append('media', imageB64);
console.log(imageB64);
form.append('status', message);
form.getLength(function(err, flength) {
console.log(flength);
if (err) {
return requestCallback(err);
}
var req = request.post({url:"https://upload.twitter.com/1.1/media/upload.json", oauth: client, host: "upload.twitter.com", protocol: "https:"}, function (err, res) {
//console.log(res);
//console.log(err);
requestCallback(err, res);
});
req._form = form;
req.setHeader('content-length', flength);
});
});
function requestCallback(err, res, body) {
if (err) {
//console.log(err);
} else {
callback();
}
}
};