HTTP“内容处置:附件"并在 iOS 网络浏览器上下载文件

HTTP quot;Content-Disposition: attachmentquot; and downloading files on iOS web browser(HTTP“内容处置:附件并在 iOS 网络浏览器上下载文件)
本文介绍了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.

附:感谢您在 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 网络浏览器上下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)