We Want to Hear From You! What Do You Want to See on the Community? Tell us here !
Forum Discussion
PoisonIvy
6 years ago
New member | Level 2
CORS Error HTTP API using Ajax
So I'm new to the Dropbox API and I've been experimenting with HTTP API calls using javascript's Ajax function. I'm currently trying to use the /create functionality but I'm encountering a CORS error.
Here's the code I'm using:
const title = "more_examples.txt"; const destination = "/"; const response = $.ajax({ url: "https://api.dropboxapi.com/2/file_requests/create",
type: "POST",
dataType: 'application/octet-stream',
async: false,
headers: {
"Authorization": "Bearer <TOKEN>",
"Content-Type": "application/json",
"data": '{"title": "' + title + '","destination": "' + destination + '","deadline": {"deadline": "2020-10-12T17:00:00Z","allow_late_uploads": "seven_days"},
"open": true}'
}
});
And here's the error:
Cross-Origin Request Blocked: The Same Origin Policy disallows
reading the remote resource at https://dl.dropboxusercontent.com/2/file_requests/create.
(Reason: CORS request did not succeed).
To make matters worse, I had previously tried downloading a file and that totally worked! Here's that code too:
const path = "example.txt";
const args = { "path": path const response = $.ajax({ url: "https://content.dropboxapi.com/2/files/download", type: "POST", dataType: 'application/octet-stream', async: false, headers: { "Authorization": "Bearer <TOKEN>",