Search code examples
javascriptxmlhttprequestdropbox-api

XHRHttpRequest to Dropbox XHR failed loading: OPTIONS


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.


Solution

  • The problem was that I was doing this at local host. Once I stuck it on a server, it worked.