gpt4 book ai didi

azure - 写入 Azure block Blob

转载 作者:行者123 更新时间:2023-12-04 16:35:34 25 4
gpt4 key购买 nike

我正在使用 PutBlock 和 PutBlockList 将数据上传到 block blob,我为此使用的代码如下:-

CloudBlobContainer container = blobStorage.GetContainerReference("devicebackups");
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
CloudBlockBlob blob = container.GetBlockBlobReference(serialNo.ToLower() + " " + dicMonths[DateTime.Now.Month]);
try
{
var serializer = new XmlSerializer(typeof(List<EnergyData>));
var stringBuilder = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(stringBuilder))
{
try
{
serializer.Serialize(writer, deviceData);
byte[] byteArray = Encoding.UTF8.GetBytes(stringBuilder.ToString());

List<string> blockIds = new List<string>();
try
{
blockIds.AddRange(blob.DownloadBlockList(BlockListingFilter.Committed).Select(b => b.Name));
}
catch (StorageClientException e)
{
if (e.ErrorCode != StorageErrorCode.BlobNotFound)
{
throw;
}
blob.Container.CreateIfNotExist();
}
var newId = Convert.ToBase64String(Encoding.UTF8.GetBytes(blockIds.Count().ToString()));
blob.PutBlock(newId, new MemoryStream(byteArray), null);
blockIds.Add(newId);
blob.PutBlockList(blockIds);
}
catch (Exception ex)
{
UT.ExceptionReporting(ex, "Error in Updating Backup Blob - writing byte array to blob");
}
}
}
catch (Exception ex)
{
UT.ExceptionReporting(ex, "Error in Updating Backup Blob - creating XmlWriter");
}
}
catch (Exception ex)
{
UT.ExceptionReporting(ex, "Error in Updating Backup Blob - getting container and blob references, serial no -" + serialNo);
}

这适用于 10 个 block ,然后在第 11 个 block 上崩溃并出现以下错误:-

StorageClientException - 指定的阻止列表无效。

InnerException = {"The remote server returned an error: (400) Bad Request."}

我在互联网上搜索了相同错误的报告,但没有找到。

任何帮助将不胜感激。

最佳答案

For a given blob, the length of the value specified for the blockid parameter must be the same size for each block.

http://msdn.microsoft.com/en-us/library/windowsazure/dd135726.aspx

前 10 个 block 的编号为 0 到 9。第 11 个 block 的编号为 10,比其长一个字符。因此,您应该更改编号方案以始终使用相同的长度。一种解决方案是将计数转换为以零填充的字符串,该字符串的长度足以容纳您期望拥有的 block 数。

但是,如果您不需要使用 block 的好处,那么您可能最好一次性写入整个 blob,而不是使用 block 。

关于azure - 写入 Azure block Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10280739/

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