Reputation: 11791
All, I am trying to find a way to download a large blob file (about 200MB) from an Asp.net MVC 4 Web Site , Here is my code snippet. Please review it .thanks.
string sBlobName ="xxxxx";
Response.ContentType="application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + sBlobName);
long lFileSize =200*1024*1024;
int iOffset = 0;
int iBufferSize = 4 * 1024 * 1024;//MB
while (iOffset < lFileSize)
{
//Chunk read blob into a byte array
var bData = StorageHelper.ChunkReadPackage(sContainerName, sPackFullPath, iOffset, iBufferSize);
Response.BinaryWrite(bData);
iOffset += bData.Length;
}
Response.Flush();
Response.End();
return new EmptyResult();
It seems After all the chunks which were read from blob were sent to client by Response.BinaryWrite(), then my Firefox could pop up the download dialog window to me .
My Questions
Why need Response.BinaryWrite() the whole content ? Is there anyway to make this process more efficiently? I mean if there is a way to download the stream in client side after the first chunk of blob was sent to client. Instead waiting all the content was sent to client .
Upvotes: 0
Views: 590