我可以授权。
我的页面上有 2 个这样的按钮:
<input type="file" id="fileToSend"/>
<input type="button" onclick="upload()" value="Upload" id="btnSend"/>
当我单击“上传”按钮时,我想将所选文件上传到 youtube。我调用这样的函数:
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);
}
});
});
}
问题是我在响应对象“mediaBodyRequired”上出现错误,就像我没有正确发送 fileStream。