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 have tried all recommendations from Jspy blog and nothing worked so far. Content-disposition brings browser in downloading mode, however nothing gets downloaded except HTML of page from which download got initiated. So my conclusion, it is pure bug from Google and we may only pray for that Google fix it. My work around was to set content type to some type coming from Accept header form mobile browser. It generally works, you can even download zip files as text.
As I wrote at downloading files from android:
Android browser will not download file in button Post events. In post events the file will be some .htm garbage file. to over come this do as below.
In download button click
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("download-file.aspx");
}
and on download-file.aspx file do as below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class mobile_download_file : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string filename = "usermanual.pdf";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + "" + filename + "");
Response.Write(Server.MapPath(Request.ApplicationPath) + "\\" + filename);
Response.TransmitFile(Server.MapPath(Request.ApplicationPath) + "\\" + filename);
Response.End();
}
}
the same can be implemented in php also.
To make any downloads work on all (and especially older) Android versions as expected, you need to...
Read my blog post for more details:
http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
In theory, the filename parameter should be set on Content-Disposition, not Content-Type. Not sure whether this will help with the Android browser.
Dmitriy (or others looking for a possible solution) if an html page is appearing in your downloaded file, I suspect this is due to the double HttpRequest GET issue. A typical scenario is the following POST, Redirect, GET model:
Android browser issues a HttpRequest POST to server (e.g. submit button or link to request a download file, filename.ext say)
Server streams the requested filename.ext to bytes, stores in a session variable, and then issues a Response.Redirect to Download.aspx, for example, to handle the response object construction
Android browser correctly sends HttpRequest GET to server for Download.aspx
Server responds with typical Content-Disposition: attachment; filename="filename.ext" style construct with the response object containing the requested filename.ext, being the bytes in the session variable.
Android download manager, I believe, then sends another HttpRequest GET to server for Download.aspx. I suspect that the download manager interprets the previous "attachment" response as a trigger to send this second GET.
Server (Download.aspx) again tries to construct the response object to send back to the browser.
Android download manager downloads filename.ext, using the response object contents from the second Download.aspx.
In many scenarios this would be fine. But if, for example, the server in the Download.aspx code does some housekeeping and removes the session variable the first time it is called, then the next time around there is no session variable. So, depending on how the code is written it is possible that the response object doesn't get explicity constructed and maybe the Response.End doesn't get called and so only the Download.aspx's html ends up being sent.
This is what we discovered using Wireshark, although I admit I am assuming it is the Android download manager that is the cause for the double GET.
I hope this explanation has been of some help.