Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > WAV File not downloading properly

Reply
Thread Tools

WAV File not downloading properly

 
 
nateastle
Guest
Posts: n/a
 
      11-27-2009
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.
 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      11-27-2009
Use rather
http://msdn.microsoft.com/en-us/libr...narywrite.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

 
Reply With Quote
 
 
 
 
nateastle
Guest
Posts: n/a
 
      11-29-2009
On Nov 27, 2:20*pm, "Patrice" <http://scribe-en.blogspot.com/> wrote:
> Use ratherhttp://msdn.microsoft.com/en-us/library/system.web.httpresponse..binar...
>
> 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


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.promptwav e);
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.

 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      11-29-2009
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


 
Reply With Quote
 
nateastle
Guest
Posts: n/a
 
      11-29-2009
On Nov 29, 5:45*am, "Patrice" <http://scribe-en.blogspot.com/> wrote:
> 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


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
 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      11-29-2009
On Nov 29, 5:48*pm, nateastle <(E-Mail Removed)> wrote:
> On Nov 29, 5:45*am, "Patrice" <http://scribe-en.blogspot.com/> wrote:
>
> > 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

>
> 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


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...
 
Reply With Quote
 
nateastle
Guest
Posts: n/a
 
      11-30-2009
On Nov 29, 11:50*am, Alexey Smirnov <(E-Mail Removed)> wrote:
> On Nov 29, 5:48*pm, nateastle <(E-Mail Removed)> wrote:
>
>
>
> > On Nov 29, 5:45*am, "Patrice" <http://scribe-en.blogspot.com/> wrote:

>
> > > 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

>
> > 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

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


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.
 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      11-30-2009
> 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

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      11-30-2009
On Nov 30, 4:23*pm, nateastle <(E-Mail Removed)> wrote:
> On Nov 29, 11:50*am, Alexey Smirnov <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Nov 29, 5:48*pm, nateastle <(E-Mail Removed)> wrote:

>
> > > On Nov 29, 5:45*am, "Patrice" <http://scribe-en.blogspot.com/> wrote:

>
> > > > 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

>
> > > 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

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

>
> 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.- Hide quoted text -
>
> - 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.
 
Reply With Quote
 
 
 
Reply

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
instead of depending on data = array('h') .. write samples 1 by 1 tow = wave.open("wav.wav", "w") '2+ Python 2 07-29-2009 06:26 PM
ASP.NET FTP Not Downloading JPEGs Properly... MU ASP .Net 4 04-01-2009 03:08 PM
CD-DA to Wav to DVD as Wav files? makbertodelete@anothermessage.com DVD Video 10 09-27-2005 08:42 PM
Substituting AOL Wav files with MSN Wav files Thaqalain Computer Support 6 07-07-2005 08:17 PM
More American Graffiti: Properly Framed, Properly Scored? Scot Gardner DVD Video 0 09-02-2003 02:28 AM



Advertisments