Im OK authorized.
I have 2 button's like this on my page:
<input type="file" id="fileToSend"/>
<input type="button" onclick="upload()" value="Upload" id="btnSend"/>
I want to upload the selected file to youtube when I click the "Upload" button. Im calling a function like this:
function upload() {
var fileStream;
var video = document.getElementById("fileToSend");
var file = video.files[0];
console.log(file);
console.log("Nombre: " + file.name);
var r = new FileReader();
r.onload = function () {
console.log("fileStream creado");
fileStream = r.result;
//console.log("FileStream: " + fileStream);
};
console.log("Creando fileStream..");
r.readAsBinaryString(file);
gapi.client.load('youtube', 'v3',
function() {
var request = gapi.client.youtube.videos.insert({
part: 'snippet, status',
resource: {
snippet: {
title: 'Video Test Title 5',
description: 'Video Test Description',
tags: ['Tag 1', 'Tag 2'],
categoryId: "22"
},
status: {
privacyStatus: "private"
}
}
}, fileStream);
request.execute(function (response) {
console.log("executing..");
var result = response.result;
console.log(response);
if (result) {
console.log("execute completed");
document.write(result);
}
});
});
}
The problem is I get al error on the response object, "mediaBodyRequired", It's like I'm not sending the fileStream correctly.
Is there a reason you can't just use the YouTube upload widget?
https://developers.google.com/youtube/youtube_upload_widget
Anyways, straight from the API reference
https://developers.google.com/youtube/v3/docs/videos/insert
badRequest mediaBodyRequired The request does not include the video content.
Another resource:
https://developers.google.com/api-client-library/javascript/samples/samples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With