Resource interpreted as Document but transferred with MIME type application/zip

后端 未结 18 2294
不思量自难忘°
不思量自难忘° 2020-11-27 10:54

With Chrome 12.0.742.112, if I redirect with the following headers:

HTTP/1.1 302 Found 
Location: http://0.0.0.0:3000/files/download.zip
Content-Type: text/h         


        
相关标签:
18条回答
  • 2020-11-27 11:15

    I encountered this same issue today with Chrome Version 30.0.1599.66 with my node.js / express.js application.

    The headers are correct, express sets them properly automatically, it works in other browsers as indicated, putting html 5 'download' attribute does not resolve, what did resolve it is going into the chrome advanced settings and checking the box "Ask where to save each file before downloading".

    After that there was no "Resource interpreted as document...." error reported as in the title of this issue so it appears that our server code is correct, it's Chrome that is incorrectly reporting that error in the console when it's set to save files to a location automatically.

    0 讨论(0)
  • 2020-11-27 11:15

    I had this issue in an ASP web site project. Adding a "Content-Length" header caused downloads to start working again in Chrome.

    0 讨论(0)
  • 2020-11-27 11:16

    In my case the file name was too long, and got the same error. Once shortened below 200 chars worked fine. (limit might be 250?)

    0 讨论(0)
  • 2020-11-27 11:17

    I solved the problem by adding target="_blank" to the link. With this, chrome opens a new tab and loads the PDF without warning even in responsive mode.

    0 讨论(0)
  • 2020-11-27 11:17

    This issue was re-appeared at Chrome 61 version. But it seems it is fixed at Chrome 62.

    I have a RewriteRule like below

    RewriteRule ^/ShowGuide/?$ https://<website>/help.pdf [L,NC,R,QSA]
    

    With Chrome 61, the PDF was not opening, in console it was showing the message

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

    We tried to add mime type in the rewrite rule as below but it didn't help.

    RewriteRule ^/ShowGuide/?$ https://<website>/help.pdf [L,NC,R,QSA, t:application/pdf]
    

    I have updated my Chrome to latest 62 version and it started to showing the PDF again. But the message is still there in the console.

    With all other browsers, it was/is working fine.

    0 讨论(0)
  • 2020-11-27 11:18

    I had a similar issue when performing a file download through Javascript. Adding the download attribute made no difference but adding target='_blank' did - I no longer get the 'Resource interpreted as Document...' console message.

    Here's my nicely simple code:

    var link = document.createElement('a');
    link.target = '_blank';
    link.href = url;
    document.body.appendChild(link); // Required for Firefox
    link.click();
    link.remove(); 
    

    I haven't tried it with direct HTML but would expect it to work.

    Note I discovered that Firefox requires the link to be appended to the document whereas Chrome will work without it.

    0 讨论(0)
提交回复
热议问题