从blob存储下载文件时出现问题

时间:2015-01-27 06:30:50

标签: c# azure azure-blob-storage

您好我必须从blob存储中下载5到6 GB的文件,在下载时我每次都会收到以下提到的错误。

Error-:

无法从传输连接读取数据:远程主机强行关闭现有连接。

My code for downloading:

protected void btn_download_Click1(object sender, EventArgs e)
{

 AccountFileTransfer = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;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 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();

}

0 个答案:

没有答案