英文:
Prevent Safari from auto extracting ZIP files (since sometimes it only extracts the first member)
问题
在从HTTP服务器提供ZIP文件时,Safari似乎会自动解压缩ZIP文件。如何通过对服务器进行更改来阻止它这样做?是否有一种构建ZIP文件的方式可以防止这种情况,或者是否有一些HTTP头可以设置?
我知道你可以配置Safari不这样做,但我正在寻找一种方法,不需要让网站访问者在下载之前采取额外步骤。
这与在https://github.com/uktrade/stream-zip/pull/42 报告的问题有关,在某些情况下,Safari似乎只会自动提取某些ZIP文件的第一个成员,而其他成员似乎会消失。想知道如何确保它根本不尝试这样做,从而规避这个明显的错误。
英文:
When serving ZIP files from an HTTP server, Safari seems to auto-unzip ZIP files. How can it be stopped from doing so via changes in the server? Is there a way of constructing ZIP files so it won't, or some HTTP header to set?
I know you can configure Safari to not do this, but looking for a method that doesn't involve the website visitor having to take extra steps before download.
This is related to the issue reported at https://github.com/uktrade/stream-zip/pull/42 where in some cases Safari seems to only auto-extract the first member of certain ZIP files and others members just seem to disappear. Wondering how to make sure it doesn't ever try to to that, and thus side-stepping the apparent bug.
答案1
得分: 1
压缩文件很可能以 MIME 类型 application/zip
(或替代的 application/x-zip-compressed
、application/zip-compressed
)形式提供,告诉客户端文件的类型。我确定如果你能摆脱这个 Content-Type,Safari 就不会知道要解压缩它。然而当我尝试在我的托管服务上这样做时,cPanel 显示“你不能更改系统定义的 MIME 类型值”!(系统为以 .zip 结尾的文件定义了 application/zip
。)我只能在该服务上添加新的 MIME 类型。希望你对你的有更多控制。
英文:
The zip files are very likely being served with the MIME type: application/zip
(or alternatives application/x-zip-compressed
, application/zip-compressed
, which tells the client what it is. I'm sure that if you could get rid of that Content-Type, then Safari would not know to extract it. However when I tried to do that on my hosting service, cPanel said "you can not alter the system defined MIME type values"! (The system defines application/zip
for files that end in .zip.) I can only add new MIME types on that service. Hopefully you have more control over yours.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论