HTTP“内容 - 处置:附件”并在iOS网络浏览器上下载文件 [英] HTTP "Content-Disposition: attachment" and downloading files on iOS web browser

查看:939
本文介绍了HTTP“内容 - 处置:附件”并在iOS网络浏览器上下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的用户能够下载PDF文件并让浏览器将其视为文件,而不仅仅是显示它(即它具有文件名,用户可以选择保存等)。以下标题似乎适用于除iOS以外的所有地方:

I want my users to be able to download a PDF file and have the browser treat it as a file, not just display it (i.e. it has a filename, user gets option to save, etc.). The following header seems to work well for this everywhere except for iOS:

Content-Disposition: attachment; filename=file.pdf

iOS只是忽略它并显示图像或文档。没什么大不了的,你可能会想,除了我在隐藏的IFRAME中这样做,作为我的下载页面的一部分,因此文档甚至从未见过,看起来下载失败。

iOS just ignores this and displays the image or document. No big deal, you might think, except I'm doing this in a hidden IFRAME as part of my download page, so the document is never even seen, and it looks like the download failed.

以跨浏览器兼容的方式处理此问题的最佳方法是什么? iOS只是忽略这个标题吗?我无法在任何地方找到任何规格或提及。

What's the best way to handle this in a cross-browser compatible manner? Does iOS just ignore this header? I can't find any spec or mention of this anywhere.

我是否需要在请求标头中检查iOS并以不同方式提供响应?我希望避免这种情况。谢谢。

Do I need to check for iOS in request headers and serve the response differently? I was hoping to avoid this. Thanks.

P.S。任何其他有关在iOS网络浏览器中下载文件等的有用提示都表示赞赏。

P.S. Any other helpful tips related to downloading files etc. in iOS web browsers are appreciated.

澄清:这是关于移动Safari浏览器浏览的常规网站。不是原生应用。

CLARIFICATION: This regarding a regular web site browsed by the mobile Safari browser. Not a native app.

推荐答案

移动版Safari浏览器不支持下载文件。

The mobile Safari browser doesn't support downloading files.

如果Safari可以显示它,它将显示。如果您安装了可以打开文件的其他应用程序,Safari会为您检测到它。

If Safari can display it, it will display. If you have installed other apps that can open the file, Safari will detect it for you.

这篇关于HTTP“内容 - 处置:附件”并在iOS网络浏览器上下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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