cloudblockblob.putblockasync给出错误:system.invalidoperationException:流的长度超过允许的长度
我正在尝试使用 CloudBlockBlob.putblockasync
方法上传大量对象。
在调用该方法时,我将获得 system.invalidoperationException:流的长度超过允许的长度。
我单独验证了块的内存流本身没有给出OOM或任何其他错误。 (IE块对象适合在内存流中)。 cloudBlockBlob.putblockasync
方法是否有任何流尺寸限制?
我在任何文档中都找不到。我正在使用 microsoft.windowsazure.storage 9.3.2,用于.net 4.5
以下是代码片段: (它在数据的测试环境中起作用,但在生产中破裂)
foreach (IList<MyDTO> chunk in chunkedDTOs)
{
string blockId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
using (var stream = new MemoryStream())
using (var sw = new StreamWriter(stream))
using (JsonWriter writer = new JsonTextWriter(sw))
{
var serializer = JsonSerializer.Create();
serializer.Serialize(writer, chunk);
await sw.FlushAsync();
stream.Position = 0;
await cloudBlockBlob.PutBlockAsync(blockId, stream, contentMD5: null, accessCondition: null,
options: null, operationContext: null, cancellationToken);
}
blockIds.Add(blockId); // ids collected to commit later
}
错误堆栈跟踪:
System.InvalidOperationException: The length of the stream exceeds the permitted length.
at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End() in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\StorageAsyncResult.cs:line 77
at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndPutBlock(IAsyncResult asyncResult) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 2079
at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass7.<CreateCallbackVoid>b__5(IAsyncResult ar) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\AsyncExtensions.cs:line 121
--- End of stack trace from previous location where exception was thrown ---
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
源泉说,作为
Microsoft.windowsazure.score.9.3.2
是一个传统库,它可能支持每个块100 MIB。由于内存流不仅如此,因此请求失败了。我减少了块大小,因此内存流的大小比100 MIB少,并且有效。
该库最后一次更新为2018年11月27日的9.3.3。因此,更新引用是没有意义的。
”稍后将在使用microsoft.azure.storage.blob库中调查。
Fount that as the
Microsoft.WindowsAzure.Storage 9.3.2
is a legacy library, it might be supporting 100 MiB per block. As the memory stream was more than this, the request was failing.https://learn.microsoft.com/en-us/azure/storage/blobs/scalability-targets#scale-targets-for-blob-storage

I reduced the chunk size so that the memory stream size is lesser that 100 MiB, and that worked.
This library was last updated to 9.3.3 on 11/27/2018. So there is no point in updating the references.
https://www.nuget.org/packages/WindowsAzure.Storage/
I would later investigate in using the Microsoft.Azure.Storage.Blob library instead.