Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have to download a file from blob storage upto 3 to 5 gb .

Below is my code:


C#
Label lblfilename = (Label)row.FindControl("lblGrid_filename");
    Label lblfilesize = (Label)row.FindControl("lblGrid_hidfileSize");
    string downloadfile = lblfilename.Text.ToString();
   // DownloadFileFromBlob(downloadfile, CONTAINER, ACCOUNTKEY);
    AccountFileTransfer = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=" + ACCOUNTNAME + ";AccountKey=" + ACCOUNTKEY);
    if (AccountFileTransfer != null)
    {
        BlobClientFileTransfer = AccountFileTransfer.CreateCloudBlobClient();
        ContainerFileTransfer = BlobClientFileTransfer.GetContainerReference(CONTAINER);
        ContainerFileTransfer.CreateIfNotExist();
        BlobRequestOptions options = new BlobRequestOptions();

        options.Timeout = new TimeSpan(0, 180, 0);
    }

    var data = Regex.Match(lblfilesize.Text.ToString(), @"\d+").Value;

    int value32;
    Int64 value64;
    var blobSize = 0L;
    var blockSize = 0L;
    var offset = 0L;
    if (int.TryParse(data, out value32))
    {

        blobSize = Convert.ToInt32(lblfilesize.Text.ToString());
    }
    else if (Int64.TryParse(data, out value64))
    {
        blobSize = Convert.ToInt64(lblfilesize.Text.ToString());

    }


    var blob = ContainerFileTransfer.GetBlockBlobReference(downloadfile);

    var sasUrl = blob.Uri.AbsoluteUri;


    CloudBlockBlob blockBlob = new CloudBlockBlob(sasUrl);

    //blobSize = Convert.ToInt32(lblfilesize.Text.ToString());
    blockSize = 5 * 1024 * 1024;
    Response.Clear();
    Response.ContentType = "APPLICATION/OCTET-STREAM";
    System.String disHeader = "Attachment; Filename=\"" + blockBlob.Name + "\"";
    //Response.AppendHeader("Content-Disposition", disHeader);

    for (offset = 0; offset < blobSize; offset += blockSize)
    {
        using (var blobStream = blockBlob.OpenRead())
        {
            if ((offset + blockSize) > blobSize)
            {
                blockSize = (blobSize - offset);
            }

            byte[] buffer = new byte[blockSize];
            blobStream.Read(buffer, 0, buffer.Length);
            Response.BinaryWrite(buffer);
            Response.Flush();
        }
    }
    Response.End();


error:
Unable to read data from the transport connection: The connection was closed.
Posted
Updated 5-Feb-15 16:29pm
v3
Comments
Sinisa Hajnal 5-Feb-15 2:17am    
There is nothing under SNAPSHOT...at a guess, I'd say you have to increase the timeout, usual problem with large downloads...or maybe destination space.
deepankarbhatnagar 5-Feb-15 7:36am    
please clarify..
Herman<T>.Instance 5-Feb-15 11:03am    
32 bit OS?
pawanprasad 6-Feb-15 23:21pm    
64 bit os

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900