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

后端 未结 18 2296
不思量自难忘°
不思量自难忘° 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:19

    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.

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

    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. :)

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

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

    0 讨论(0)
  • 2020-11-27 11: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.

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

    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 + "\"");
    ...
    
    0 讨论(0)
  • 2020-11-27 11:33

    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);
    
    0 讨论(0)
提交回复
热议问题