ASP.NET Web API StreamContent - make browser show download progress

asp.net, asp.net-web-api2, browser, c#, stream

Solution

Turned out that my implementation was correct. I closed fiddler and everything worked as expected. Don't know if fiddler somehow waits for the entire response to complete before it sends it through its proxy - at least, that would explain why the browser stays in the "resolving host" state until the entire file has been downloaded.

Problem

From an ASP.NET Web Api 2.x controller I'm am serving files using an instance of the `StreamContent` type. When a file is requested, its blob is located in the database, and a blob stream is opened. The blob stream is then used as input to a `StreamContent` instance. Boiled down, my controller action looks similar to this: ``` [HttpGet] [Route("{blobId}")] public HttpResponseMessage DownloadBlob(int blobId) { // ... find the blob in DB and open the 'myBlobStream' based on the given id var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(myBlobStream) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentLength = myBlobStream.Length; result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "foo.txt", Size = myBlobStream.Length }; return result; } ``` When I hit the endpoint in Chrome (v. 35) it says that it is resolving the host (localhost) and when the file has downloaded it then appears in the download bar. However, I am wondering what is needed to enable Chrome (or any other browser) to show the download progress? I thought this would be fixed by included the header information like content-type, content-length, and content-disposition, but from what I have tried, that does not make any difference.

Original source