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.
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;
– Netinho Santos
@Netinhosantos Didn’t work out !
– Victor Augusto
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
– Netinho Santos
https://stackoverflow.com/a/12145505/4713574
– Rovann Linhalis
It worked out Thank you!
– Victor Augusto