Javascript video upload.

59 views
Skip to first unread message

Thomas Gebert

unread,
Oct 4, 2013, 6:44:50 PM10/4/13
to google-ajax...@googlegroups.com
Hello all!  
 
I am currently trying to upload a video to youtube purely client-side.  I have managed to get Oauth working (following this example: https://developers.google.com/youtube/v3/code_samples/javascript ).  I have also gotten *very* close to getting the actual upload to work doing this 


 <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? 

 
Reply all
Reply to author
Forward
0 new messages