1. 2015 is going to be a great year for Android! Why wait??
    Samsung Galaxy Note 5 | Samsung Galaxy S6 | HTC One M9
  2. New Forum Created: Samsung Gear VR!

android phone download issue from asp.net website


  1. pchalla

    pchalla New Member

    hi guys,

    any help is gr8tly appreciated (this is very urgent )

    There seems to be an issue with streaming file downloads on the android phone. If I create a share for a file called photo.zip and try to download it from the "download.aspx" page I only get 13kb of the file then the download stops and says

    Advertisement
    :
  2. DreadedDev

    DreadedDev New Member

    The reason it is always the same file is that it is sending the webpage as the actual file instead, no idea why, found this thread as I am having the same problem, it works correctly on all other phones, browsers, etc but not Android.... it even works on iPhones.... and nothing normally works on those!!
  3. Aselby

    Aselby Active Member

    I think your problem is your content-dispostion statment

    context.Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName)


    thats what I use and it works for me (expect on android 2.1 which returns the wrong name)

    I also let asp firgure out the content size

    and I flush between the headers and the content then after the file

    It took a lot of trial and error to get it to work but thats what ended up actually working
  4. I ran into this same issue as well.

    Doing some research on the Android browser, the browser does not determine the file type from the file extension, like most desktop browsers. The Android browser determines the filetype through the ContentType property on the Response. To circumvent this, I just created a static dictionary initialized in Global.asax that sets mime types by file extension, like so....

    public static void SetUpDictionary()
    {
    _FileExtentionToMimeTypeDictionary = new Dictionary<string, string>(33);
    _FileExtentionToMimeTypeDictionary.Add("doc", "application/msword");
    _FileExtentionToMimeTypeDictionary.Add("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
    _FileExtentionToMimeTypeDictionary.Add("jpeg", "image/jpeg");
    _FileExtentionToMimeTypeDictionary.Add("jpg", "image/jpeg");
    _FileExtentionToMimeTypeDictionary.Add("mpeg", "video/mpeg");
    _FileExtentionToMimeTypeDictionary.Add("mpg", "video/mpeg");
    _FileExtentionToMimeTypeDictionary.Add("pdf", "application/pdf");
    _FileExtentionToMimeTypeDictionary.Add("zip", "application/zip");
    _FileExtentionToMimeTypeDictionary.Add("xls", "application/excel");
    _FileExtentionToMimeTypeDictionary.Add("xlw", "application/excel");
    _FileExtentionToMimeTypeDictionary.Add("xlm", "application/excel");
    _FileExtentionToMimeTypeDictionary.Add("xll", "application/excel");
    _FileExtentionToMimeTypeDictionary.Add("xlt", "application/excel");
    _FileExtentionToMimeTypeDictionary.Add("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    _FileExtentionToMimeTypeDictionary.Add("xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12");
    _FileExtentionToMimeTypeDictionary.Add("tiff", "image/tiff");
    _FileExtentionToMimeTypeDictionary.Add("tif", "image/tiff");
    _FileExtentionToMimeTypeDictionary.Add("gif", "image/gif");
    _FileExtentionToMimeTypeDictionary.Add("flv", "video/x-flv");
    _FileExtentionToMimeTypeDictionary.Add("pot", "application/powerpoint");
    _FileExtentionToMimeTypeDictionary.Add("ppt", "application/powerpoint");
    _FileExtentionToMimeTypeDictionary.Add("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
    _FileExtentionToMimeTypeDictionary.Add("bmp", "image/bmp");
    _FileExtentionToMimeTypeDictionary.Add("html", "text/html");
    _FileExtentionToMimeTypeDictionary.Add("htm", "text/html");
    _FileExtentionToMimeTypeDictionary.Add("htmls", "text/html");
    _FileExtentionToMimeTypeDictionary.Add("rt", "text/richtext");
    _FileExtentionToMimeTypeDictionary.Add("rtf", "text/richtext");
    _FileExtentionToMimeTypeDictionary.Add("rtx", "text/richtext");
    _FileExtentionToMimeTypeDictionary.Add("txt", "text/plain");
    _FileExtentionToMimeTypeDictionary.Add("text", "text/plain");
    _FileExtentionToMimeTypeDictionary.Add("xml", "text/xml");
    }

    Our company took those as the most uploaded file types, but there are hundreds more. By changing your ContentType, hopefully you'll get some different results.
  5. Jpsy

    Jpsy New Member

    @DavidAndroidDev:
    You do not need to create this list of ext-to-mime relations if you already send the mime-type with a HTTP ContentType header! According to my tests it is also not true that Android does not look at the filename extension. You might end up with "The content being downloaded is not supported by the phone" if your extension is unknown or lowercased.

    @all:
    To make sure your downloads work as expected on all Android versions, make sure you...
    1. set the ContentType to application/octet-stream
    2. put the filename value in double quotes
    3. put the filename extension in UPPERCASE

    Read my blog for more details:
    Android and the HTTP download file headers | DigiBlog

    Cheers, Jpsy.
  6. etia86

    etia86 Member

    Hi there. i have the same problem with you. I cannot download file from android from my asp page. The different between my page is i'm using asp and you are using asp.net.

    I have try instruction that you give us in the above quote. But, the problem is still the same. I cannot download file from my page while browsing using Samsung galaxy tab (android ver 3.1). But, i can download from my page using IE ver 7.

    Can you help me to solve this problem? :confused:
  7. etia86

    etia86 Member

    Hello there. I really need someone to help me on this.
  8. StevePayne

    StevePayne New Member

    For those people that are finding that an html page is appearing in their downloaded file, I suspect this is due to a 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
    - Android download manager, I believe, then sends another HttpRequest GET to server for Download.aspx. I suspect that the download manager interprets the "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 constructed 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.
  9. Sorry to bump an old thread, but I've noticed when downloading my grades from my school's aspx site using the stock ICS browser, I get a file with the .aspx extension. The weird thing for me is that when I download the exact same file using Chrome on ICS, I get the .pdf and it works fine. Hopefully this will help any fix?
Loading...

Share This Page