Allow CORS for webroot files!

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)

ERROR 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

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer