我已经实现了以下异步 blob 上传方法来上传多个 block 。
var container = GetContainer(containerName);
var blob = container.GetBlockBlobReference(blobName);
String[] base64EncodedBlockIds = new String[10];// 10- number of Blocks
//To upload the blocks in parallel - 10 parallel blocks
ParallelLoopResult parallelLoopResult = Parallel.For(0,10, i =>
{
String base64EncodedBlockId = Convert.ToBase64String(System.BitConverter.GetBytes(i));
byte[] bytesMemoryStream = GetBytesFromStream(stream);
using (MemoryStream memoryStream = new MemoryStream(bytesMemoryStream))
{
blob.PutBlock(base64EncodedBlockId, memoryStream, null);// throws an exception "The value for one of the HTTP headers is not in the correct format"
}
base64EncodedBlockIds[i] = base64EncodedBlockId;
});
blob.PutBlockList(base64EncodedBlockIds);
它抛出异常“HTTP header 之一的值格式不正确”。
需要您的意见
问候, 维韦克
最佳答案
blob 中的 BlockID 必须具有相同的长度(字符数)。 BlockID“10”比其他的长,这可能是您问题的根源。
一种解决方案是将 BlockID 用零填充到相同的长度。
关于asynchronous - Blob.UploadAsync 方法上的 StorageClientException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12565533/