I'm trying to upload an image to dropbox using jquery, but I get an error for cors policy block. Is there another way to upload?
My code:
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://www.dropbox.com/sh/y7rp1h0cbquydix/AADnOhInfieO19mK_H3q71IJa?dl=0');
xhr.setRequestHeader('Authorization', 'Bearer ' + <ACCESS_TOKEN>);
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
path: '/' + imgPath,
mode: 'add',
autorename: true,
mute: false
}));
xhr.send(imgPath);