File without extension

Asked

Viewed 178 times

0

I have an application that streams an audio file on a page, but when trying to download the file it comes without extension.

Follow the code I use :

   public HttpResponseMessage Get(string filename)
    {
        AudioSteam audio = new AudioSteam(filename);

       var response = Request.CreateResponse();
        response.Content = new PushStreamContent(async (Stream outputStream, HttpContent content, TransportContext context) =>
        {
            try
            {
                var buffer = new byte[65536];

                using (var video = File.Open(audio._filename, FileMode.Open, FileAccess.Read))
                {
                    var length = (int)video.Length;
                    var bytesRead = 1;

                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            finally
            {
                outputStream.Close();
            }
        });

        return response;
    }

Follow the image of the file downloaded in my via my page. inserir a descrição da imagem aqui

As you can see the file comes with the download name and without the extension, as implement for which it has the original name of the file and the extension?

  • Try: Response.Content.Headers.ContentDisposition.Filename = "file_my_filename"; Return Response;

  • @Netinhosantos Didn’t work out !

  • response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); 
 response.Content.Headers.ContentDisposition.FileName = "nome_do_meu_arquivo; 
 response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); Source: http://www.pashov.net/code/Download+large+files+with+Web+Api+as+a+relay

  • https://stackoverflow.com/a/12145505/4713574

  • It worked out Thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.