Joe.wang
Joe.wang

Reputation: 11791

Download Azure Blob in Web Site

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

Answers (1)

Joe.wang
Joe.wang

Reputation: 11791

Response.BufferOutput = false; It works.

Upvotes: 1

Related Questions