C: / FakePath проблема с загрузкой DROPBOX - PullRequest
0 голосов
/ 15 апреля 2019

Согласно DROPBOX, это должно работать для загрузки, но все это только загрузка объявления в текстовом файле, содержащем не более, чем c: / 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);
}
...