Allow CORS for webroot files!

Posted July 23, 2020 520 views

I need to fetch and download files from webroot/datafiles/images/filename.jpg, but I got CORS error!

The download works when the link is opened through navigator (not fetch http)

Access to XMLHttpRequest at ’’ from origin ’http://localhost:8080’ has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.

export function download(file: File) {
  return api.get(normalizeFileUrl(, {
    responseType: 'blob',
  }).then(response => {
    FileDownload(response, `${file.nome}`);

I’m using cakephp as API it’s already configured CORS!

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!