Facebook API: cannot upload video thumbnail

Viewed 79

I'm calling the Facebook API from a Node.js server in order to upload a video. The video has a thumbnail hosted on another server. I want to read the file from the server, pass it as a FormData to /{page-id}/videos.

I'm able to get the file and convert it to base64 data, however, everytime that I call the API I get the following error:

(#100) Invalid image format. It should be an image file data.

Here's my code:

try {
  const data = await httpUtilBase.get(thumbnailUrl, { responseType: 'arraybuffer' });
  thumbnailData = `data:${data.headers['content-type']};base64,${Buffer.from(data.data).toString('base64')}`;
} catch {
  return next(new ErrorResponse('Cannot fetch thumbnail url', httpStatus.BAD_REQUEST));
}

const formData = new FormData();

formData.append('url', url);
formData.append('title', title);
formData.append('published', 'false');
formData.append('thumb', thumbnailData);
formData.append('access_token', facebookUtil.decryptToken(page));

I make the call to /{page-id}/videos just after and it always fails. I don't understand what the format should be.

0 Answers
Related