Search code examples
javascriptdownloadhttp-accept-header

Warning when setting window.location to download a file


I am setting the window.location to download a file ("/foo/bar"). Now, the download works in google chrome, but it emits this warning:

Resource interpreted as Document but transferred with MIME type application/csv:

These are the response headers that are set according to google chrome:

Content-Description:File Transfer  
Content-Disposition:attachment; filename="foo.csv"  
Content-Length:29  
Content-Type:application/csv
Date:Sun, 14 Dec 2014 20:53:33 GMT  
Server:http-kit  

Any ideas if I can set the accept header on js side anyhow to omit this warning?


Solution

  • You can use an anchor tag

    <a href="fileLink" download="filename">Download</a>
    

    make sure for the download attribute you put the extension type of the file like .html, .css, .js whatever it is