I’m trying to upload image as base64 string in form data. After INIT and APPEND, the FINALIZE call is successful, after which i POST status/update with media_id returned from all the thee calls. Only the text or status part is posted on twitter but not the image.
Here is my code:
OAuth.popup("twitter").then(function(result) {
console.log("Result from twitter popup", result);
let data = new FormData();
data.append('command', 'INIT');
data.append('total_bytes', t.sizeInBytes);
data.append('media_type', 'image/jpeg');
result.post('https://upload.twitter.com/1.1/media/upload.json', {
data: data,
cache: false,
processData: false,
contentType: false
})
.then(initResult => {
// INIT successfully sent
console.log("Result in INIT", initResult);
let dataa = new FormData();
dataa.append('command', 'APPEND');
dataa.append('media_id', initResult.media_id_string);
dataa.append('segment_index', '0');
dataa.append('media_data', t.file);
result.post('https://upload.twitter.com/1.1/media/upload.json', {
headers: {'Content-Transfer-Encoding': 'base64'},
data: dataa,
cache: false,
processData: false,
contentType: false
})
.then(appendResult => {
console.log("Result in APPEND", appendResult, initResult.media_id_string);
let final = new FormData();
final.append('command', 'FINALIZE');
final.append('media_id', initResult.media_id_string);
result.post('https://upload.twitter.com/1.1/media/upload.json', {
data: final,
cache: false,
processData: false,
contentType: false
})
.then(finalizeResult => {
console.log("Finalize result", finalizeResult);
})
.then(tweet => {
let tweetData = new FormData();
tweetData.append('status', Date());
tweetData.append('media_id', initResult.media_id_string);
result.post('https://api.twitter.com/1.1/statuses/update.json', {
data: tweetData,
cache: false,
processData: false,
contentType: false
})
.then(tweet => {
console.log("Tweeted", tweet);
});
})
});
});
})
I successfully validated the base64 string that I’m attaching to form data to produce the image, the string is valid.
Anyone who can help/clarify?