Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old January 13th, 2011, 04:30 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default android phone download issue from asp.net website

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 “Download Complete”. If I put that same file in the root of the site and browse to that file directly by going to “www.domain.com/photo.zip” I get the entire file downloaded.

I am not sure how other websites do it but our only option is to stream the file since our data storage server is not directly accessible over HTTP.

I have tried at least 10 different ways to stream a download and they all result in the same 13kb file being download. And another twist, if I download a share that is a 3kb file after I download the file my phone shows the file as being 13kb.

the code I wrote in .aspx page is as follows:
the file could have any entension - I dont know that.
protectedvoid DownloadFile()
{
//this is a streaming location of the file
string file = "C:/Inetpub/rails_apps/Treb_store/1/railssetupguides.sitx";
FileInfo f = newFileInfo(file)
string fileName = u.StripFilePath(file);

Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType =
"application/octet-stream";
Response.AddHeader(
"content-disposition", "attachment;
filename=\"" + (fileName) + "\"");
Response.AddHeader(
"content-length", f.Length.ToString());
Response.TransmitFile(file);
Response.End();
}

thanks

Advertisements
pchalla is offline  
Reply With Quote
sponsored links
Old March 25th, 2011, 05:42 AM   #2 (permalink)
New Member
 
Join Date: Mar 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!!
DreadedDev is offline  
Reply With Quote
Old March 25th, 2011, 09:04 PM   #3 (permalink)
Junior Member
 
Join Date: Mar 2010
Location: Indiana
Posts: 34
 
Device(s): Droid
Carrier: Not Provided

Thanks: 0
Thanked 9 Times in 8 Posts
Default

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
Aselby is offline  
Reply With Quote
Old April 12th, 2011, 12:45 PM   #4 (permalink)
Junior Member
 
Join Date: Sep 2010
Posts: 21
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 2 Times in 1 Post
Default

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.
DavidAndroidDev is offline  
Reply With Quote
Old April 20th, 2011, 05:02 AM   #5 (permalink)
New Member
 
Join Date: Apr 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

@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.
Jpsy is offline  
Reply With Quote
Old November 17th, 2011, 08:25 PM   #6 (permalink)
New Member
 
Join Date: Nov 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

Quote:
Originally Posted by Jpsy View Post
@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.
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?
etia86 is offline  
Reply With Quote
Old November 24th, 2011, 09:55 PM   #7 (permalink)
New Member
 
Join Date: Nov 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello there. I really need someone to help me on this.
etia86 is offline  
Reply With Quote
Old December 20th, 2011, 10:57 AM   #8 (permalink)
New Member
 
Join Date: Dec 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
StevePayne is offline  
Reply With Quote
Old July 15th, 2012, 01:56 AM   #9 (permalink)
New Member
 
Join Date: Jun 2012
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
joshbgosh10592 is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:35 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.