WAV File not downloading properly

Discussion in 'ASP .Net' started by nateastle, Nov 27, 2009.

  1. nateastle

    nateastle Guest

    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.
     
    nateastle, Nov 27, 2009
    #1
    1. Advertising

  2. nateastle

    Patrice Guest

    Patrice, Nov 27, 2009
    #2
    1. Advertising

  3. nateastle

    nateastle Guest

    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.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.
     
    nateastle, Nov 29, 2009
    #3
  4. nateastle

    Patrice Guest

    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
     
    Patrice, Nov 29, 2009
    #4
  5. nateastle

    nateastle Guest

    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
     
    nateastle, Nov 29, 2009
    #5
  6. On Nov 29, 5:48 pm, nateastle <> 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...
     
    Alexey Smirnov, Nov 29, 2009
    #6
  7. nateastle

    nateastle Guest

    On Nov 29, 11:50 am, Alexey Smirnov <> wrote:
    > On Nov 29, 5:48 pm, nateastle <> 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.
     
    nateastle, Nov 30, 2009
    #7
  8. nateastle

    Patrice Guest

    > 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
     
    Patrice, Nov 30, 2009
    #8
  9. On Nov 30, 4:23 pm, nateastle <> wrote:
    > On Nov 29, 11:50 am, Alexey Smirnov <> wrote:
    >
    >
    >
    >
    >
    > > On Nov 29, 5:48 pm, nateastle <> 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.
     
    Alexey Smirnov, Nov 30, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    14,004
    Jonathan Bromley
    Apr 8, 2005
  2. Domingo
    Replies:
    1
    Views:
    507
    Andrew Thompson
    Jul 17, 2004
  3. MU
    Replies:
    4
    Views:
    1,750
    Martin Honnen
    Apr 1, 2009
  4. '2+
    Replies:
    2
    Views:
    495
  5. Li Chen
    Replies:
    0
    Views:
    105
    Li Chen
    Sep 10, 2008
Loading...

Share This Page