views:

26

answers:

1

Hi all,

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();

However, 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.

Many thanks in advance

A: 

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.

matt-dot-net
Thank you very much matt-dot-net! Learned a lot from your reply. I'm gonna implement this later on and i will let you know if it worked (will mark as answer)!
Tweek