C:/ fakepath问题与DROPBOX上传

时间:2019-04-14 22:05:09

标签: javascript dropbox-api dropbox-js

根据DROPBOX的说明,该功能适用​​于上传,但所有操作仅是上传一个文本文件,仅包含c:/ fakepath。我知道为什么会发生fakepath安全问题,但是我不明白为什么直接进入obj.value

时我什至无法使它工作
<input id="upfile_1" type="file" value="upload" name="image_1" style="display: nones" onchange="sub_1(this)"/>

function sub_1(obj){
    var file = obj.value;   

    var xhr = new XMLHttpRequest();

    xhr.upload.onprogress = function(evt) {
        var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
        // Upload in progress. Do something here with the percent complete.
    };

    xhr.onload = function() {
        if (xhr.status === 200) {
            var fileInfo = JSON.parse(xhr.response);
            // Upload succeeded. Do something here with the file info.
        }
        else {
            var errorMessage = xhr.response || 'Unable to upload file';
            // Upload failed. Do something here with the error.
        }
    };

    xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
    xhr.setRequestHeader('Authorization', 'Bearer ' + 'token');
    xhr.setRequestHeader('Content-Type', 'application/octet-stream');
    xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
        path: '/' +  file.name,
        mode: 'add',
        autorename: true,
        mute: false
    }));
    xhr.send(file);
}

0 个答案:

没有答案