2c2c
2c2c

Reputation: 4864

Youtube API thumbnail upload isn't working

Using google's node api library, I can't seem to get thumbnail uploading to work. I've used it extensively for uploading and listing videos without any issues.

let req = Youtube.thumbnails.set(
  {
    videoId: video_id,
    media: {
      mimeType: "image/jpeg",
      body: "test.jpg"
    }
  },
  (err, thumbResponse) => {
    if (err) {
      console.log(err);
      process.exit(1);
    }
    console.log("thumbnail uploaded");
    console.log(thumbResponse);
  }
);

This results in Error: The provided image content is invalid.

Using a stream instead results in Error: write after end error.

The image I'm using is a typical 1280x720 image that I've tested by manually uploading to youtube fine. video_id is set to a video i own

Upvotes: 4

Views: 1195

Answers (1)

Sumit Dey
Sumit Dey

Reputation: 149

you need to as readStream

const data = youtubeClient.thumbnails.set(
    {
      videoId: VIDEO_ID,

      media: {
        mimeType: "image/jpeg",
        body: fs.createReadStream("./public/thumbnail.jpg"),
      },
    },
    (err, data) => {
      console.log(err, data);
    }
  );

Upvotes: 1

Related Questions