0

I'm using javascript to fetch some data with the fetch() method:

fetch(url, {
      method: 'GET',
      mode: 'cors', 
      cache: 'no-cache',       
      credentials: 'same-origin', 
      headers: myHeaders,
      referrer: 'no-referrer',
     }

However it is giving me the following error:

Error:- Access to fetch at 'https://www.dropbox.com/s/v2pca6kq8nsqmso/abb5c48dae55560e4ae7d41af7bfdc50.jpg?raw=1' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

What am I missing?

2

1 Answer 1

8

www.dropbox.com doesn't allow CORS. It doesn't include the CORS headers. This is intentional.
You can use the CDN link at domain dl.dropboxusercontent.com instead, which does.

Note that this kind of usage is not supported by DropBox and may or may not be discontinued or changed without notice.

fetch('https://dl.dropboxusercontent.com/s/v2pca6kq8nsqmso/abb5c48dae55560e4ae7d41af7bfdc50.jpg?raw=1', {
  method: 'GET',
  mode: 'cors',
  cache: 'no-cache',
  credentials: 'same-origin',
  headers: {},
  referrer: 'no-referrer',
}).then(x => x.blob().then(y => console.log(y)))

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.