Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / November 2009

Tip: Looking for answers? Try searching our database.

WAV File not downloading properly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nateastle - 27 Nov 2009 19:25 GMT
I have a application that stores a wav file into the database. I
retrieve the wav file through a web service call that gets the file.
When I try to send the file through the response stream it seems the
file gets changed. If I save the file to disk it works properly.

Here is my latest endeavor

Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" +
"test.wav");
BinaryWriter bw = new BinaryWriter(Response.OutputStream);
bw.Write(objPromptStorageOut.promptwave);
bw.Close();
Response.ContentType = ATACUtility.getMimeFromFile
(objPromptStorageOut.promptwave);
Response.End();

The file that gets downloaded is 2 times the size of the original
file.

Here is  how I write it to disk
using (BinaryWriter binWriter = new BinaryWriter(File.Open(@"C:
\nater.wav", FileMode.Create)))
           {

               binWriter.Write(objPromptStorageOut.promptwave);
           }

that currently works.
Patrice - 27 Nov 2009 21:20 GMT
Use rather
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.binarywrite.aspx

Keep in mind that the Response outputstream is intended to write
"characters" and applies the encoding defined in your web.config file.

Response.BinaryWrite will write the bytes without any encoding...

--
Patrice
nateastle - 29 Nov 2009 03:37 GMT
> Use ratherhttp://msdn.microsoft.com/en-us/library/system.web.httpresponse.binar...
>
[quoted text clipped - 5 lines]
> --
> Patrice

Thank you for your reply. I have tried your suggestion and it still
did not work.

Here is what I tried:

Response.AddHeader("Content-Disposition", "attachment; filename=" +
"nate.wav");
Response.BinaryWrite(objPromptStorageOut.promptwave);
Response.Flush();
Response.End();

and that generated a file of 155,365 bytes when the original file was
80,120
if I add

Response.ContentType = "audio/wav";
Response.AddHeader("Content-Length",
(objPromptStorageOut.promptwave.Length).ToString());

then I get the correct file size but the file is unplayable.
Patrice - 29 Nov 2009 12:45 GMT
Could it be a similar encoding problem when you read the file ? How do you
read the file in objPromptStorageOut.PromptWave ?

My approach would be to validate each step that is :
- to start by streaming a well known byte array (let's take 16 bytes such as
0x00 up to 0xf0). You'll easily see if it works and moreover if it doesn't
work you'll be able to quickly check what changed in the content.
- if it works read the same content from a file. If it doesn't work you'll
know you have a problem in how you read the file.
- then once that work, it should work with the actual file.
--
Patrice
nateastle - 29 Nov 2009 16:48 GMT
> Could it be a similar encoding problem when you read the file ? How do you
> read the file in objPromptStorageOut.PromptWave ?
[quoted text clipped - 8 lines]
> --
> Patrice

The file is stored in blob column in an oracle database, I have a web
service that returns the byte array back. If I write the file directly
to the disk in the web service it plays, if I write it directly to the
disk on the website it works, the only thing that doesn't work is when
I try to send the file in the response. When I look at the first bytes
of the file, I get the correct header for the wav file. I will try
with a smaller file and see where it is going wrong.

Nate
Alexey Smirnov - 29 Nov 2009 18:50 GMT
> > Could it be a similar encoding problem when you read the file ? How do you
> > read the file in objPromptStorageOut.PromptWave ?
[quoted text clipped - 18 lines]
>
> Nate

Can it be a problem with authorization?
http://forums.asp.net/p/1243133/2276691.aspx#2276691

If it doesn't help try to set "application/x-msdownload" instead if
"audio/wav", this is a special type that should prompt the user with
an open-or-save dialog.

Response.AddHeader("content-disposition", "attachment;
filename=test.wav")
Response.ContentType = "application/x-msdownload"
Response.BinaryWrite...
nateastle - 30 Nov 2009 15:23 GMT
> > > Could it be a similar encoding problem when you read the file ? How do you
> > > read the file in objPromptStorageOut.PromptWave ?
[quoted text clipped - 29 lines]
> Response.ContentType = "application/x-msdownload"
> Response.BinaryWrite...

I created a test project with only the hyper link and the same calls
and that seemed to work. I am going to say it has something to do with
the security or something else on the page that is changing the
response. I tried changing the file to grant all users access to the
aspx file and that did not work.
Patrice - 30 Nov 2009 16:03 GMT
> I created a test project with only the hyper link and the same calls
> and that seemed to work. I am going to say it has something to do with
> the security or something else on the page that is changing the
> response. I tried changing the file to grant all users access to the
> aspx file and that did not work.

Looks a tough one. Now I would try to use a blob wiht those 16 values 0x0 to
0xf0 and see how it behaves. Save the file on disk and use an hexa file
viewer to see what was changed in the file...

Good luck.
--
Patrice
Alexey Smirnov - 30 Nov 2009 20:36 GMT
> > > > Could it be a similar encoding problem when you read the file ? How do you
> > > > read the file in objPromptStorageOut.PromptWave ?
[quoted text clipped - 37 lines]
>
> - Show quoted text -

One thing I forgot to mention is that the ClearContent method does not
clear header information. If you do not use Clear or ClearHeaders
before calling ClearContent then add Response.ClearHeaders() to ensure
that no other headers are sent with the current response.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.