Hello all!
<form method="post" enctype="multipart/form-data">
<input type="file" id="fileToSend"/>
<input type="button" onclick="createVideo()" value="Upload" id="btnSend"/>
</form>
function createVideo() {
var fileStream;
var video = document.getElementById("fileToSend");
var file = video.files[0];
console.log(file);
console.log("Nombre: " + file.name);
var r = new FileReader();
var that = gapi
r.onload = function () {
console.log("fileStream creado");
fileStream = r.result;
//console.log("FileStream: " + fileStream);
gapi.client.load('youtube', 'v3',
function() {
var request = gapi.client.youtube.videos.insert({
part: 'snippet, status',
resource: {
"snippet": {
"title": "My video title",
"description": "This is a description of my video",
"tags": ["cool", "video", "more keywords"],
"categoryId": 22,
"mediaBody": fileStream
},
"status": {
"privacyStatus": "public",
"embeddable": true,
"license": "youtube"
},
}
})
request.execute(function (response) {
console.log("executing..");
var result = response.result;
console.log(response);
if (result) {
console.log("execute completed");
document.write(result);
}
});
});
}
console.log("Creando fileStream..");
r.readAsBinaryString(file);
When I say very close, I mean that I can actually log into my youtube account, and see that it tried to post the video, and it'll infinitely say it's "processing". The response I get back is an error saying "mediaBodyRequired", which upon googling means "video ain't attaching". That's all well and good, but I don't really know where or how to attach the video...Does anyone here know of a good way to go about doing that?