youtube.thumbnails.set isn't working
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
any news?
same problem
any news?
@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);
}
);
}
original attempt was with a stream. didn't help. lmk if it worked for you personally
worked! thx. needs to be a buffer.
thank you @bantini
@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,
}
});