4

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

2c2c
  • 4,694
  • 7
  • 22
  • 33
  • 1
    Hmm, so, did you try to do `body: fs.createReadStream("test.jpg")`? I'm pretty sure [it expects a stream](https://github.com/google/google-api-nodejs-client/blob/a23cb742729166227791904cf1b5dc03feb83b4c/apis/youtube/v3.ts#L2583). – Ionică Bizău Aug 07 '17 at 07:49
  • Using a stream instead results in `Error: write after end` error. I'm not very stream savvy so it's not really intelligible what this means. No issues uploading a video through streams though – 2c2c Aug 07 '17 at 08:21
  • Can you post your example when using a stream? That error is quite general: when you do `.write()` after calling `.end()` (that may happen in the Google APIs client). – Ionică Bizău Aug 07 '17 at 08:48
  • https://gist.github.com/2c2c/0736e87b6853b42828ad8480382ab427 i dont do anything with the stream (i just modelled what worked for uploading video) – 2c2c Aug 07 '17 at 08:55
  • Makes sense... This looks like a bug. Maybe you can [open an issue here](https://github.com/google/google-api-nodejs-client/issues/new). The parameters object is important. – Ionică Bizău Aug 07 '17 at 09:02
  • @2c2c Did you fix your issue? I saw your github issue is still open. We are having the same issue, using curl in bash. We didn't change anything and it just stopped working recently. Curious thing is that it works in Postman. Have you tried that by any chance? – APE Oct 04 '17 at 05:18
  • @APE I havent fixed the issue and havent tried sending a raw request. ill revisit.. eventually :-) – 2c2c Oct 04 '17 at 08:20

1 Answers1

1

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);
    }
  );
Sumit Dey
  • 119
  • 1
  • 1
  • 6