Asp.net Download file on mobile platform
I've some files stored in a SQL database. When a user visits a url with the given ID, the BLOB data is retrieved from the database to the webbrower via:
Byte[] myData = b.BlobContent;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", b.SizeInBytes.ToString());
Response.BinaryWrite(myData);
Response.End();
Howeve开发者_JAVA百科r, the iPhone (Safari) can't download a *.txt and *.doc file. It says: "Safari can't download this file". A pdf can(!) be downloaded and viewed.
On Android none of the files can be downloaded.
Is this because the iPhone and Android just can't handle all files? Or am I doing something wrong in the Response.
The content type of application/octent-stream is not appropriate for .txt and .doc files. for .txt you want to use "text/plain" and .doc files you want "application/msword" I suggest that you store the Content-Type value in your database. Here is a good reference for mime types. If you are accepting the files through the FileUpload control the PostedFile object should tell you the contentn type.
EDIT 1: Also, you should not need to set the content-length, as ASP.Net will do this for you.
精彩评论