I can't figure out how to use the gapi.client.youtube.thumbnails.set client-side JavaScript? All the examples I've found are for node.js and use the following syntax:
gapi.client.youtube.thumbnails.set({
videoId: 'xxxx',
media: {
mimeType: "image/jpeg",
body: fs.createReadStream("some-file.jpg"),
}
})
Obviously the fs.createReadStream isn't available in client-side JavaScript. How can I use that API with an image that the user loads via an <input file="type"> element? I've tried everything I could think of as the value of the body media key:
fileInputNodefileInputNode.filesfileInputNode.files[0]fileInputNode.files[0].arrayBufferfileInputNode.files[0].arrayBuffer()fileInputNode.files[0].streamfileInputNode.files[0].stream()- base64 encoded data for the image
- raw data for the image
where fileInputNode is the HTML element for the file input. In all cases the call to gapi.client.youtube.thumbnails.set does not send any data in the request body, and only sets the videoId query parameter. So not surprisingly the request fails with "The request does not include the image content."
Does anybody know how to use this method?
You can give a try with
readAsArrayBufferfromFileReader. Here is a demo: