views:

381

answers:

4

Hi,

I have a sql database that stores media files (.avi f.e.). I extract the video in a aspx page (VIDEOPAGE) as a byte array and send it to another web page calling this one (It has to be this way), and showing the video using an html object tag presenting a windows media player control.

The syntax I use is:

Response.ContentType = contentType;
Response.AddHeader("Content-Disposition", string.Format("attachment; filename ={0}",myAttachment.FileName));
Response.OutputStream.Write(myAttachment.Attachment, 0, myAttachment.Attachment.Length)

This works perfectly fine for all mpeg and wmv files, but fails on avi!! The contentType variable contains the CORRECT content type (and this I know because of the following:

When I don't use an object tag but simply load the VIDEOPAGE page with an avi file from the database and the above syntax, it displays a "do you want to open.." dialog box, I click ok, and the video DOES SHOW in WMP.

I tried to change the Content-Disposition to hidden and also inline. Nothing..

Any ideas?

A: 

Try removing the Response.AddHeader("Content-Disposition", ... line.

Darin Dimitrov
+1  A: 

The Content Disposition header should look like:

Content-Disposition: attachment; filename="filename.avi"

Maybe I'm misreading your code, but it looks like:

a) You don't have the space after Content-Disposition and

b) you don't have the file name in quotes.

This seems unlikely, since you are only having the problem with AVI files, but since mpeg and wmv files are more native to the OS, this might be a coincidence that they work even when it shouldn't.

One way to test this is to change the content type to something neutral like ".pdf" and seeing what happens.

Anthony
Yes, you're reading it wrong. Response.AddHeader doesn't take a full-header string ("Content-Disposition: attachment;..."), but rather two strings: the header name ("Content-Disposition") and the header value ("attachment;...").
Ross Patterson
A: 

Firstly, if you're just embedding the video on a web page, you do not need the Content-Disposition header, so just remove that line.

Secondly, can you please show us which Content-Type values you are using for each video type.

That your browser opened the video in Windows Media Player is not proof that you are using the correct type, as Internet Explorer and some other browsers can ignore the Content-Type header and rely on the file extension. So the fact that your filename is .avi is enough for IE to play the video in WMP.

Christopher
+1  A: 

Make sure you've set the content-type correctly AND that you include a well-known filetype-suffix in the filename (e.g., "blah.avi"). Browsers often use the filetype-suffix if they don't recognize the content-type or if they don't have an association set up for it.

Ross Patterson