我使用以下代码以MB为单位定义块blob大小,然后下载此文件。工作正常。
protected void btn_download_Click1(object sender, EventArgs e)
{
Button btndownloadrow = (Button)sender;
GridViewRow row = (GridViewRow)btndownloadrow.NamingContainer;
Label lblfilename = (Label)row.FindControl("lblGrid_filename");
string downloadfile = lblfilename.Text.ToString();
AccountFileTransfer = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=" + ACCOUNTNAME + ";AccountKey=" + ACCOUNTKEY);
if (AccountFileTransfer != null)
{
BlobClientFileTransfer = AccountFileTransfer.CreateCloudBlobClient();
ContainerFileTransfer = BlobClientFileTransfer.GetContainerReference(CONTAINER);
ContainerFileTransfer.CreateIfNotExist();
}
var blob = ContainerFileTransfer.GetBlockBlobReference(downloadfile);
var sasUrl = blob.Uri.AbsoluteUri;
CloudBlockBlob blockBlob = new CloudBlockBlob(sasUrl);
var blobSize = 551* 1024 * 1024; // Block blob size of 551 MB
int blockSize = 1024 * 1024 * 1; // chunk of size 1 MB
Response.Clear();
Response.ContentType = "APPLICATION/OCTET-STREAM";
System.String disHeader = "Attachment; Filename=\"" + blockBlob.Name + "\"";
Response.AppendHeader("Content-Disposition", disHeader);
for (long offset = 0; offset < blobSize; offset += blockSize)
{
using (var blobStream = blockBlob.OpenRead())
{
if ((offset + blockSize) > blobSize)
blockSize = (int)(blobSize - offset);
byte[] buffer = new byte[blockSize];
blobStream.Read(buffer, 0, buffer.Length);
Response.BinaryWrite(buffer);
Response.Flush();
}
}
Response.End();
}
我面临的问题是,当我尝试用GB定义块blob大小时,我遇到了溢出错误。我正在尝试下载大小约为3 GB的文件。我用这个: - var blobSize = 3558 * 1024 * 1024; //试图在这里定义大约3 GB的块blob大小我得到溢出错误 你可以帮助我,以便我可以用GB定义块blob大小,这样我就可以使用块blob存储从azure下载文件。
答案 0 :(得分:0)
我找到了上述错误的答案(溢出错误)。
我为摆脱上述错误所做的是我刚刚附加了&#34; L&#34;对于Long类型,错误消失了。
var blobSize = 3558L * 1024 * 1024;
希望它可以帮助某人。
感谢。