question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uploadMedia fails with buffer input

See original GitHub issue

Hi, I’ve been trying to use this wrapper for the upload media endpoint in a project and it works pretty well for local files but when I try to pass a buffer created from binary data it prompts:

Error: Failed to process media

This is how I get the binary data:

const getVideoBuffer = (previewUrl: string) => {
  return new Promise((resolve, reject) => {
    request.defaults({ encoding: null });
    request.get(previewUrl!, async (error, response, body) => {
      if (error) {
        reject(new Error(`Something went wrong getting binary data from preview url ${error}`));
      }
      resolve(Buffer.from(body));
    });
  });
};

Here I get the buffer and start the upload:

 const buffer: any = await getVideoBuffer(previewUrl || '');
 const mediaId = await client.v1.uploadMedia(buffer, { type: 'mp4', target: 'tweet'});
 const tweet = await client.v1.tweet('Hello!', { media_ids: mediaId });
 console.log(tweet);

Am I missing something? Thanks in advance

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
ghostcommented, Dec 3, 2021

Hi @savannahar68, we just ended up using axios, here:

const res: any = await axios.get(previewUrl || '', { responseType: 'arraybuffer' });
log.info('Content fetched...');
const buffer = res.data;
const mediaId = await client.v1.uploadMedia(buffer, { type: 'longmp4', target: 'tweet' });

Then you would call

const tweet = await client.v1.tweet("Your tweet", { media_ids: mediaId });

Good luck!

1reaction
ghostcommented, Sep 27, 2021

It was the request package, just noticed that is deprecated. Thanks a lot @alkihis , that solved the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Posts failing to save due to server issues - Buffer Help Center
To test if this is causing the issue, open Buffer in an incognito window, and then try scheduling the post again. If the...
Read more >
Uploading and sharing links to videos - Buffer Help Center
There are two ways to share videos to your social channels through Buffer. The first way is to upload your video within the...
Read more >
Error: Oops! Please edit the post - alter the copy/text, re-name ...
This could be by editing and changing the copy/text of the post, editing hashtags, removing links, re-uploading the media, and trying to publish...
Read more >
Error: Oops! A timeout occurred while downloading the media ...
Rename the video file to something like video1. Upload the newly renamed video to the newly created post. Try sending out the new...
Read more >
Troubleshooting failed Instagram posts - Buffer Help Center
The workaround to resolve this issue is to switch your Instagram account back to a personal profile and then reconvert it to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found