小编Nic*_*aul的帖子

从浏览器上传视频到youtube

我还好.

我的页面上有2个这样的按钮:

<input type="file" id="fileToSend"/>
<input type="button" onclick="upload()" value="Upload" id="btnSend"/>
Run Code Online (Sandbox Code Playgroud)

当我点击"上传"按钮时,我想将所选文件上传到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 …
Run Code Online (Sandbox Code Playgroud)

javascript upload youtube-api youtube-javascript-api

8
推荐指数
1
解决办法
4120
查看次数