google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

youtube.thumbnails.set isn't working

Open 2c2c opened this issue 9 years ago • 8 comments

Hey. Trying to use youtube.thumbnails.set with videoId and media object properly set is giving me errors.

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

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

At https://stackoverflow.com/questions/45535611/youtube-api-thumbnail-upload-isnt-working it was recommended I post here. full code sample at gist.github.com/2c2c/0736e87b6853b42828ad8480382ab427

2c2c avatar Aug 07 '17 09:08 2c2c

any news?

sebseb7 avatar Oct 30 '17 21:10 sebseb7

same problem

cot97 avatar Nov 06 '17 06:11 cot97

any news?

cot97 avatar Nov 11 '17 16:11 cot97

@2c2c @sebseb7 @cot97 Try using a synchronous stream.

var upload_thumbnail = function(auth){
   var youtube = google.youtube('v3');
   youtube.thumbnails.set(
   {
     auth: auth,
     videoId: 'U49C3_DEWFM',
     media: {
       mimeType: 'image/jpeg',
       body: fs.readFileSync('youtube.jpg')
     },
   },
   (err, thumbResponse) => {
     if (err) {
       console.log("Error response");
       console.log(err);
       process.exit(1);
     }
     console.log("thumbnail uploaded");
     console.log(thumbResponse);
   }
 );
}

bantini avatar Nov 13 '17 20:11 bantini

original attempt was with a stream. didn't help. lmk if it worked for you personally

2c2c avatar Nov 13 '17 23:11 2c2c

worked! thx. needs to be a buffer.

sebseb7 avatar Nov 14 '17 23:11 sebseb7

thank you @bantini

cot97 avatar Nov 15 '17 07:11 cot97

@bantini 's solution didn't work for me, but using createReadStream() did.

const data = fs.createReadStream("thumbnail.jpg");

service.thumbnails.set({
  videoId: video_id,
    media: {
      mimeType: "image/jpeg",
      body: data,
    }
});

leemustache avatar Jan 31 '21 11:01 leemustache