Reputation: 813
According to DROPBOX this is supposed to work for uploads, but all it's only uploading ad a text file with nothing more than c:/fakepath. I understand why the fakepath security thing happens, but i don't get why i can't even get it to work when i go straight to obj.value
<input id="upfile_1" type="file" value="upload" name="image_1" style="display: nones" onchange="sub_1(this)"/>
and
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);
}
Upvotes: 0
Views: 67