Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 402
700 Software Avatar asked Jan 12 '11 22:01

700 Software


People also ask

Why are files not downloading on Android?

Go to Settings > Storage and check the Android's total and available storage space. If you are running low, try uninstalling any apps, videos, pictures, or other media. This is definitely a possibility you are unable to download any attachments, apps, and picks, and why the usual tricks aren't working.

How do I force a file to download instead of open in browser?

Click on "Settings" and you'll see a new page pop up in your Chrome browser window. Scroll down to Advanced Settings, click Downloads, and clear your Auto Open options. Next time you download an item, it will be saved instead of opened automatically.

Why do downloads fail on phone?

Downloads will fail if the internet connection cuts out, so make sure you have a strong internet connection. You could try disconnecting your device from the internet and reconnecting to see if that helps. If you're using WiFi, resetting the network at the router can also make a difference.


1 Answers

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/

like image 116
Jpsy Avatar answered Sep 19 '22 04:09

Jpsy