214

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/html; charset=utf-8
Cache-Control: no-cache
X-Ua-Compatible: IE=Edge
X-Runtime: 0.157964
Content-Length: 0
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Date: Tue, 05 Jul 2011 18:42:25 GMT
Connection: Keep-Alive

Which if followed returns the following header:

HTTP/1.1 200 OK 
Last-Modified: Tue, 05 Jul 2011 18:18:30 GMT
Content-Type: application/zip
Content-Length: 150014
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Date: Tue, 05 Jul 2011 18:44:47 GMT
Connection: Keep-Alive

Chrome will not redirect, nor change the previous page, it'll just report the following warning in the console:

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

The process works correctly in Firefox, and also works fine in Chrome if I open a new tab and go directly to http://0.0.0.0:3000/files/download.zip. Am I doing something wrong, or is this a bug/quirk of Chrome?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Ashley Williams
  • 6,770
  • 4
  • 35
  • 42
  • 1
    Related: [Chrome says "Resource interpreted as script but transferred with MIME type text/plain.", what gives?](http://stackoverflow.com/q/3467404) – blahdiblah Mar 27 '13 at 23:48

21 Answers21

178

You can specify the HTML5 download attribute in your <a> tag.

<a href="http://example.com/archive.zip" download>Export</a>

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download

Roy Hyunjin Han
  • 4,725
  • 2
  • 30
  • 23
  • 3
    "download" attribute is not support in ie or some other browser. if you have a other options please help me – Renish Khunt Feb 17 '15 at 12:43
  • 3
    That fixes Chrome, but breaks other browsers. My Android phones won't download from that kind of link. – Betty Aug 28 '15 at 11:20
  • 40
    sigh. **THIS 'FIX' DOES NOT WORK FOR MOST BROWSERS** - only Chrome. And it's 2016, so don't expect it to anytime soon either. – a20 May 24 '16 at 09:35
  • problem with this is actually you can't use it in a system where you want only logging in user to download the file and generate a user-specific link for your downloads. – NeoHBz Sep 22 '17 at 11:15
  • It's a pity this doesn't apply to forms, so you could POST form contents and have it result in a file download without Chrome complaining about this warning. – Adam Reis Feb 03 '19 at 05:12
  • 2
    Doesn't make a difference in Chrome 2019 – Michael Rogers Feb 27 '19 at 20:59
  • 32
    @all It's 2035 (I've come from future) and there is no computer to support this. – Ali Farhoudi Apr 17 '19 at 09:01
  • iOS does not support it and now its 2019 - so nope and nope. https://caniuse.com/#search=download (@Brian) – Olof_t May 13 '19 at 09:39
  • 1
    That caniuse.com link actually shows that browser support is very good these days, all things considered. Seems like a good solution to me. – Dave Yarwood May 22 '19 at 18:46
  • @AliFarhoudi Now that the majority support it as of the year of 2020, let’s see…. – Константин Ван Aug 23 '19 at 08:51
  • By the way Chrome seemingly does not suppress the warning if the resource to download does not have the same _origin_. – Константин Ван Aug 23 '19 at 16:29
  • this wont work if you trigger the download via `window.location.assign('download-zip?filename=' + filename)` and not the anchor link, for instance i click a button to send an ajax call to zip selected files for download and once all are zipped the ajax response function will trigger the download using the above javascript , and it would throw the warning in the console – Muhammad Omer Aslam Aug 29 '19 at 02:34
  • This is a link. And you could/should put the link in a form. If you use form attribute enctype="multipart/form-data", you will not get the dreadful error. Example:
    download
    – RWC Jan 11 '21 at 18:55
36

In your request header, you have sent Content-Type: text/html which means that you'd like to interpret the response as HTML. Now if even server send you PDF files, your browser tries to understand it as HTML. That's the problem. I'm searching to see what the reason could be. :)

Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • I've tried sending it as `Content-Type: application/zip` with no avail, it still tries to process it as a 'Document'. It's probably also worth pointing out that the zip URL is dynamic in my app, so it's nothing to do with caching. – Ashley Williams Jul 05 '11 at 19:01
  • 1
    Thanks! Could it be something to do with Chrome sending the `Accept` request header as `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`, perhaps? I'm absolutely stumped here, I really am! – Ashley Williams Jul 05 '11 at 19:08
  • 7
    No, in `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8` there is a part which says that Chrome accepts almost everything (`*/*`). – Saeed Neamati Jul 05 '11 at 19:23
  • 3
    What are you talking about? There is no request header in the question. Both of them are response headers. – doubleDown Aug 12 '17 at 18:30
  • And why is the browser so stupid to request `text/html` when this will be a PDF? I didn't tell text/html anywhere to the browser. – Csaba Toth May 28 '18 at 19:26
  • 1
    And I am sitting here wondering why this should be an answer but not a comment ? – alegria Jan 31 '20 at 07:47
27

I could not find anywhere just an explanation of the message by itself. Here is my interpretation.

As far as I understand, Chrome was expecting some material it could possibly display (a document), but it obtained something it could not display (or something it was told not to display).

This is both a question of how the document was declared at the HTML page level in href (see the download attribute in Roy's message) and how it is declared within the server's answer by the means of HTTP headers (in particular Content-Disposition). This is a question of contract, as opposed to hope and expectation.

To continue on Evan's way, I've experienced that:

Content-type: application/pdf
Content-disposition: attachment; filename=some.pdf

is just inconsistent with:

<a href='some.pdf'>

Chrome will cry Resource interpreted as document but transferred…

Actually, the attachment disposition just means this: the browser shall not interpret the link, but rather store it somewhere for other—hidden—purposes. Here above, either download is missing beside href, or Content-disposition must be removed from the headers. It depends on whether we want the browser to render the document or not.

Hope this helps.

2540625
  • 11,022
  • 8
  • 52
  • 58
Champignac
  • 695
  • 7
  • 7
26

I experienced this problem when serving up a PDF file (MIME type application/pdf) and solved it by setting the Content-Disposition header, e.g.:

Content-Disposition: attachment; filename=foo.pdf

Hope that helps.

Evan
  • 2,282
  • 2
  • 19
  • 21
23

I've fixed this…by simply opening a new tab.

Why it wasn't working I'm not entirely sure, but it could have something to do with how Chrome deals with multiple downloads on a page, perhaps it thought they were spam and just ignored them.

Ashley Williams
  • 6,770
  • 4
  • 35
  • 42
  • 9
    What do you mean you "opened a new tab"??? You manually opened a new browser window and pasted the download URL in there? – Tony R Aug 23 '12 at 16:06
  • 2
    Yes, exactly. I assumed it was a bug in the application-state of the particular tab. – Ashley Williams Sep 12 '12 at 15:09
  • 55
    I wouldn't expect the user to open a new tab... And I don't find opening one to download a file elegant either. – Yassir Ennazk Sep 25 '12 at 17:50
  • I had the same problem, I do not open a new tab for the download, but closed and reopened the tab with the download link. Pretty sneaky. – topless Oct 26 '12 at 12:24
  • @joram - window.open creates a pop-over window which gets blocked by browsers. This isn't an effective solution for file downloads. Window.location.assign('') is a better solution. – tim-montague Feb 23 '15 at 10:42
  • 29
    @Joram et. al. - opening a tab for a download (using target '_blank') - does not solve the problem, it just transfers the "Resource intrepreted as Document" console warning message to a new tab. Sweeping under the rug is not s solution. – colm.anseo Mar 26 '15 at 18:03
  • 1
    This clearly does not solve the original answer. Seriously... What would I put in the user doc "copy the url, open a new tab, paste the url, ..."? Business down. – Stranded Kid Jan 11 '16 at 10:31
  • 1
    @StrandedKid If I remember correctly, opening a new tab fixed the issue permanently, I wasn't able to recreate it after that. – Ashley Williams Jan 11 '16 at 10:37
  • Read @colminator comments right upon there, opening in a new tab does not fix anything, and never did. – Stranded Kid Jan 11 '16 at 11:05
  • 1
    @StrandedKid It did for me. When I say I opened a new tab, I went to the original page and clicked download, and it worked as expected, not that I pasted the file URL into a new tab. If you'd like to speculate why that could be the case I'd love to hear it...it certainly puzzled me at the time! – Ashley Williams Jan 11 '16 at 11:14
  • Awesome works. Just add target="_blank" in your a tag – Faris Rayhan Aug 27 '16 at 03:11
  • window.open('http://example.com/archive.zip', '_blank'); workes fine,in my case it shows save popup box in chrome – Akhil S Kamath Nov 24 '16 at 07:39
  • By adding target="_blank" to the link, that will then work without having to specify the "download" attribute like in the other answer. – stradled Apr 15 '17 at 11:23
  • This problem occurred to me when I got a message about not allowing the page to download multiple documents. – juharr Jul 14 '17 at 14:36
11

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.

Elliveny
  • 2,159
  • 1
  • 20
  • 28
  • 5
    just a warning, a target = '_blank' will trigger IE 11's popup prevention mechanism... – RobM Jul 23 '19 at 09:15
  • FYI, I did test it with direct HTML in Chrome (Version 87.0.4280.141, 64-bit) and it did not work. – RWC Jan 11 '21 at 18:03
9

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.

JohnC
  • 3,938
  • 7
  • 41
  • 48
4

I encountered this when I assigned src="image_url" in an iframe. It seems that iframe interprets it as a document but it is not. That's why it displays a warning.

Carmela
  • 687
  • 1
  • 8
  • 15
  • could you please say me how did you fixed it? as i m facing the same problem here when using an iframe – Shikha thakur Jul 04 '16 at 09:25
  • I used form data: `var photoData = new FormData();` and then set the property `contentType: false` in my ajax request. The post request will be: `Content-Disposition: form-data;` And the content-type `Content-Type: text/html` – Carmela Jul 04 '16 at 09:55
4

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.

AS Mackay
  • 2,831
  • 9
  • 19
  • 25
med
  • 49
  • 1
  • 2
    I did this and it worked: `window.open(href, '_blank');` and the new tab auto closes after the download. – crichavin Feb 05 '20 at 17:10
2

Just ran into this and none of the other information I could find helped: it was a stupid error: I was sending output to the browser before starting the file download. Surprisingly, I found no helpful errors found (like "headers already sent" etc.). Hopefully, this saves someone else some grief!

user6096790
  • 380
  • 4
  • 8
1

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

R. Salisbury
  • 1,954
  • 16
  • 17
1

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.

Asif Nowaj
  • 346
  • 2
  • 9
1

The problem

I had similar problem. Got message in js

Resource interpreted as Document but transferred with MIME type text/csv

But I also got message in chrome console

Mixed Content: The site at 'https://my-site/' was loaded over a secure connection, but the file at 'https://my-site/Download?id=99a50c7b' was redirected through an insecure connection. This file should be served over HTTPS. This download has been blocked

It says here that you need to use an secure connection (but scheme is https in message already, strangely...).

The problem is that href for file downloading builded on server side. And this href used http in my case.

The solution

So I changed scheme to https when build href for file downloading.

milkyWay
  • 106
  • 1
  • 4
0

After a couple of csv file downloads (lots of tests) chrome asked whether to allow more downloads from this page. I just dismissed the window. After that chrome did not download the file any more but the console sayed:

"Resource interpreted as Document but transferred with MIME type text/csv"

I could solve that issue by restarting chrome (completely Ctrl-Shift-Q).

[Update] Not sure why this post was deleted but it provided the solution for me. I had gotten the message earlier about trying to download multiple files and must have answered no. I got the "Resource interpreted..." message until I restarted the browser; then it worked perfectly. For some cases, this may be the right answer.

Brian Deterling
  • 13,556
  • 4
  • 55
  • 59
paul
  • 51
  • 1
  • 3
0

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?)

holdfenytolvaj
  • 5,637
  • 1
  • 17
  • 10
0

I got this error because I was serving from my file system. Once I started with a http server chrome could figure it out.

Rashi Abramson
  • 1,127
  • 8
  • 16
0

I was experiencing the same trouble with a download manager I created. The problem I was having involved the file name being too long and the extension being clipped off.

Example: File Name : Organizational Protocols and Other Things That are Important.pd

<?php
  header("Content-Disposition: attachment; filename=$File_Name");
?>

Solution: Increased the MySQL database field to 255 to store the file name, and performed a length check before saving the blob. If the length > 255 trim it down to 250 and add the file extension.

eradima
  • 81
  • 4
0

Try below code and I hope this will work for you.

var Interval = setInterval(function () {
                if (ReportViewer) {
                    ReportViewer.prototype.PrintReport = function () {
                        switch (this.defaultPrintFormat) {
                            case "Default":
                                this.DefaultPrint();
                                break;
                            case "PDF":
                                this.PrintAs("PDF");
                                previewFrame = document.getElementById(this.previewFrameID);
                                previewFrame.onload = function () { previewFrame.contentDocument.execCommand("print", true, null); }
                                break;
                        }
                    };
                    clearInterval(Interval);
                }
            }, 1000);
Faraz Babakhel
  • 654
  • 5
  • 14
0

I've faced this today, and my issue was that my Content-Disposition tag was wrongly set. It looks like for both pdf & application/x-zip-compressed, you're supposed to set it to inline instead of attachment.

So to set your header, Java code would look like this:

...
String fileName = "myFileName.zip";
String contentDisposition = "attachment";
if ("application/pdf".equals(contentType)
    || "application/x-zip-compressed".equals(contentType)) {
    contentDisposition = "inline";
}
response.addHeader("Content-Disposition", contentDisposition + "; filename=\"" + fileName + "\"");
...
Olivier B.
  • 91
  • 2
0

The problem

I literally quote Saeed Neamati (https://stackoverflow.com/a/6587434/760777):

In your request header, you have sent Content-Type: text/html which means that you'd like to interpret the response as HTML. Now if even server send you PDF files, your browser tries to understand it as HTML.

The solution

Send the bloody correct header. Send the correct mime type of the file. Period!

How?

Aaah. That totally depends on what you are doing (OS, language).

My problem was with a dynamically created download link in javascript. The link is for downloading an mp3 file. An mp3 file is not a document, neither is a pdf, a zip file, a flac file and the list goes on.

So I created the link like this:

<form method="get" action="test.mp3"> 
  <a href="#" onclick="this.closest(form).submit();return false;" target="_blank">
    <span class="material-icons">
      download
    </span>
  </a>
</form>

and I changed it to this:

<form method="get" action="test.mp3" enctype="multipart/form-data"> 
  <a href="#" onclick="this.closest(form).submit();return false;" target="_blank">
    <span class="material-icons">
      download
    </span>
  </a>
</form>

Problem solved. Adding an extra attribute to the form tag solved it. But there is no generic solution. There are many different scenario's. When you send a file from the server (you created it dynamically with a language like CX#, Java, PHP), you have to send the correct header(s) with it.

Side note: And be careful not to send anything (text!) before you send your header(s).

RWC
  • 4,697
  • 2
  • 22
  • 29
-1

I got the same error, the solution was to put the attribute

target = "_ blank"

Finally :

<a href="/uploads/file.*" target="_blank">Download</a>

Where * is the extension of your file to download.

  • 1
    this is not a solution. It just opens a new tab and download the file in that tab. Any error / warning occurred also would have been reported in that tab's debug console and not in the present tab's debug console. Now, you just don't see the problem. But, actually it is not fixed. – domino_katrino Feb 03 '21 at 08:19