I'm sorry if this is a duplicate of another question but i have looked and not found one so here goes. If this is a duplicate, then please post a link to the original so I may take a look.
When I attempt to use XMLHttpRequest to transfer a file to my dropbox I get a XHR failed loading OPTIONS error. I am not using ajax which is why I believe this is not a duplicate of previously asked questions.
I copied the code here for my code: https://blogs.dropbox.com/developers/2016/03/how-formio-uses-dropbox-as-a-file-backend-for-javascript-apps/
but here's my code:
var xhr = new XMLHttpRequest();
var passedData = new Array("one", "two", "three")
var filename = "test";
var file = new File(passedData, filename);
xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
xhr.setRequestHeader('Authorization', 'Bearer ' + 'AccessToken');
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
path: '/' + file.name,
mode: 'overwrite',
autorename: false,
mute: false,
}));
xhr.send(file);
Full Error: VM639 framework.js:82 XHR failed loading: OPTIONS "https://content.dropboxapi.com/2/files/upload". upload @ VM639 framework.js:82 onclick @ View.html:675
I just realized I forgot to mention that this was working just fine until march 25th. Might be irrelevant but I wouldn't know.
The above works fine, but the problem is when I paste it into my main script. I'm calling it the same exact way, with a button, and sending the same file, but i get that message.
XMLHttpRequestis technically making an Ajax request. Can you add the full error so that we know why the XHR fails?xhr.onload = function() { if (xhr.status !== 200) { var errorMessage = xhr.response || 'Unable to upload file'; console.error('Failed with status (' + xhr.status + ') - error: ' + errorMessage ); } };(beforexhr.open). And see what it outputs in console?xhr.onerror = function(event) { console.error('Error with status (' + event.target.status + ')'); }, or look at the network tab in the developper console for meaningful infos about the error.