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
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.
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. :)
I got this error because I was serving from my file system. Once I started with a http server chrome could figure it out.
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.
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 + "\"");
...
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);