Zip Mime Type出现无法识别 [英] Zip Mime Type appears unrecognised

查看:83
本文介绍了Zip Mime Type出现无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图返回一个zip文件,作为通过浏览器的流.这可以与其他类型的文件(例如Excel文件)配合使用,但是当我开始处理zip文件时,我无法让浏览器识别它是zip.

I'm trying to return a zip file, as a stream over a browser. This works fine with other types of files (e.g. Excel files) but when I start dealing with zip files I can't get my browsers to recognise that it's a zip.

在我的测试机上运行的Firefox和IE都提示输入哪个程序打开文件. zip文件关联的默认设置为资源管理器".

Both Firefox and IE running on my test machine prompt, asking what program to open the file with. Explorer is set as the default for the zip file association.

IE不会报告太多,但是Firefox告诉我文件类型是

IE doesn't report very much back, Firefox however tells me what the file type is a

应用程序/邮政编码

application/zip

据我所知,

是zip文件的正确mime类型.我唯一没有设置的是扩展名,因此该文件仅被称为"Test"而不是"Test.zip",但据我所知,应该全部由mime类型来确定.

which as far as I can tell is the correct mime type for a zip file. The only thing I don't have set is the extension, so the file is just called 'Test' rather than 'Test.zip' but as far as I was aware that should all be figured out by the mime type.

有人对可能出什么问题有任何想法吗?

Anyone have any ideas on what might be going wrong?

推荐答案

您应该随文件一起发送,确保包含文件扩展名:

You should send the file with, ensuring the file extension is included:

Content-disposition: attachment; filename=Test.zip

作为标题.

在C#中:

Response.ContentType = "application/zip";
Response.AddHeader("Content-Length", contentLength.ToString());
Response.AddHeader("Content-disposition", "attachment; filename=" + fileName);

if (Request.UserAgent.Contains("MSIE"))
{
    Response.AddHeader("Content-Transfer-Encoding", "binary");
}

这篇关于Zip Mime Type出现无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆