Avoiding content type issues when downloading a file via browser on Android

Bryan Field picture Bryan Field · Jan 12, 2011 · Viewed 52.5k times · Source

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.

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

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

Answer

Jpsy picture Jpsy · Apr 20, 2011

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

  1. set the ContentType to application/octet-stream
  2. put the Content-Disposition filename value in double quotes
  3. write the Content-Disposition filename extension in UPPERCASE

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