gpt4 book ai didi

c# - Windows Azure : Storage Client Exception Unhandled

转载 作者:行者123 更新时间:2023-12-03 01:58:34 26 4
gpt4 key购买 nike

我正在编写一个代码,用于使用 block 将大文件上传到 blob...当我测试它时,它给了我一个 StorageClientException

它指出:请求输入之一超出范围。

我在这行代码中遇到了这个异常:

blob.PutBlock(block, ms, null);

这是我的代码:

protected void ButUploadBlocks_click(object sender, EventArgs e)
{

// store upladed file as a blob storage
if (uplFileUpload.HasFile)
{
name = uplFileUpload.FileName;
byte[] byteArray = uplFileUpload.FileBytes;
Int64 contentLength = byteArray.Length;
int numBytesPerBlock = 250 *1024; // 250KB per block
int blocksCount = (int)Math.Ceiling((double)contentLength / numBytesPerBlock); // number of blocks
MemoryStream ms ;
List<string>BlockIds = new List<string>();
string block;
int offset = 0;

// get refernce to the cloud blob container
CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents");

// set the name for the uploading files
string UploadDocName = name;

// get the blob reference and set the metadata properties
CloudBlockBlob blob = blobContainer.GetBlockBlobReference(UploadDocName);
blob.Properties.ContentType = uplFileUpload.PostedFile.ContentType;

for (int i = 0; i < blocksCount; i++, offset = offset + numBytesPerBlock)
{
block = Convert.ToBase64String(BitConverter.GetBytes(i));
ms = new MemoryStream();
ms.Write(byteArray, offset, numBytesPerBlock);

blob.PutBlock(block, ms, null);
BlockIds.Add(block);
}

blob.PutBlockList(BlockIds);

blob.Metadata["FILETYPE"] = "text";
}
}

谁能告诉我如何解决这个问题...

最佳答案

我认为您必须执行 ms.Position = 0 才能在上传之前将流恢复到开头。 (否则,PutBlock 可能会尝试从流中读取并发现它已经在末尾了。)

关于c# - Windows Azure : Storage Client Exception Unhandled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2627316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com