Android browser/webview bug? Content-Disposition: attachment; filename="xyz.txt"

Anil Pais picture Anil Pais · Oct 22, 2010 · Viewed 9.8k times · Source

So an android browser or a webview works fine with urls like this - abc.com/xyz.txt

However, if your URL looks like this - abc.com/xyz.php and what's sent to the browser in the headers is - Content-Disposition: attachment; filename="xyz.txt", then the Android browsers and web view seems to get terribly confused.

It looks like it saves the correct file name on the phone, but the contents is filled with the webpage that was previously being viewed. This works perfectly well on PC based browsers and on an iPhone and Blackberry, it's only a problem on the Android 2.1 and 2.2 (haven't tested others).

Anyone have a solution? Will be very grateful. I really don't want to start storing static files and want to generate my download content on the fly. The log on the phone has revealed no clues.


Here's what's sent by the server to the browser

===================== start content ====================================
HTTP/1.1 200 OK
Date: Thu, 21 Oct 2010 21:22:11 GMT
Server: Apache
Content-Disposition: attachment; filename="Wafty.txt"
Content-length: 30
Content-Type: text/plain; charset=ISO-8859-1

Hello this is a test of a file
========= There was no carriage return at the end of the above line ====

Answer

user902411 picture user902411 · Aug 29, 2011

Use:

Content-Disposition: attachment;filename="xyz.txt"

Do not use (mind extra space):

Content-Disposition: attachment;  filename="xyz.txt"