在Android上通过浏览器下载文件时,避免内容类型问题 [英] Avoiding content type issues when downloading a file via browser on Android

查看:143
本文介绍了在Android上通过浏览器下载文件时,避免内容类型问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个文件通过我的webapp可用于浏览器,我通常只是将URL设置为像 http://website.com/webapp/download/89347/image.jpg 。然后我设置HTTP头 Content-Type:application / octet-stream;文件名= image.jpg 内容处置:附件

If I have a file made available to a browser through my webapp, I normally just set the URL to something like http://website.com/webapp/download/89347/image.jpg. I then set the HTTP headers Content-Type: application/octet-stream; filename=image.jpg and Content-Disposition: Attachment.

然而, Android。看来我可以让文件下载的唯一方法是设置 Content-Type:image / jpg 。否则,文件名称<未知> 并出现错误

However, on the Android. It seems the only way I can get the file to download is to set Content-Type: image/jpg. Otherwise the file name says <Unknown> and an error comes


下载不成功

无法下载。此手机不支持该内容

Download unsuccessful
Cannot download. The content is not supported on this phone

有没有办法让Android可以通过浏览器下载和打开文件,而不保留一个mime类型的列表?

Is there any way I can get Android to download and open the file through the browser without keeping a list of mime types?

推荐答案

要使所有(特别是较旧的)Android版本的任何下载在预期的情况下工作,您需要to ...

To make any downloads work on all (and especially older) Android versions as expected, you need to...


  1. 将ContentType设置为application / octet-stream

  2. 将Content-双引号中的处理文件名值

  3. 在UPPERCASE中写入Content-Disposition文件扩展名

读取我的博文更多的细节:

http://digiblog.de/2011/04/19/android-and-the-download-file-headers/

Read my blog post for more details:
http://digiblog.de/2011/04/19/android-and-the-download-file-headers/

这篇关于在Android上通过浏览器下载文件时,避免内容类型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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