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

后端 未结 18 2406
不思量自难忘°
不思量自难忘° 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: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 + "\"");
    ...
    

提交回复
热议问题