gpt4 book ai didi

c# - 如何将附加 blob 上传到 azure 而不会出现大小限制异常?

转载 作者:行者123 更新时间:2023-12-03 05:21:55 26 4
gpt4 key购买 nike

public async Task<string> UploadDataAsync<T>(CloudBlobContainer container, string relativeUrl, List<T> reportData, string mimeType, string data, ILogger log)
{
string absoluteUri = string.Empty;
byte[] bytes = Encoding.ASCII.GetBytes(data);
using (var ms = new MemoryStream())
{
using (StreamWriter sw = new StreamWriter(ms))
{
sw.Write(data);
sw.Flush();
ms.Position = 0;

CloudAppendBlob blob;
blob = container.GetAppendBlobReference(relativeUrl);
if (await blob.ExistsAsync())
{
await blob.AppendBlockAsync(ms);
absoluteUri = blob.StorageUri.PrimaryUri.AbsoluteUri;
}
else
{
CloudAppendBlob appBlob = await CreateEmptyFileAsync(container, relativeUrl, reportData, mimeType, log);
await appBlob.AppendBlockAsync(ms);
absoluteUri = appBlob.StorageUri.PrimaryUri.AbsoluteUri;
}
}
}

return absoluteUri;
}

获取此异常 -

Microsoft.WindowsAzure.Storage.StorageException:“请求正文太大,超出了最大允许限制。”[外部代码]UploadService.cs 中的 PDCGeoTabFunction.Services.UploadService.UploadDataAsync(Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer、字符串、System.Collections.Generic.List、字符串、字符串、Microsoft.Extensions.Logging.ILogger)[外部代码]PDCGeoTabFunction.Services.SyncGeoTabDataService.GetZone(Geotab.Checkmate.API,字符串,字符串,字符串,Microsoft.Extensions.Logging.ILogger,字符串,字符串,字符串,字符串,System.Collections.Generic.List )

请帮忙。

最佳答案

您收到此错误的原因很可能是您尝试上传的数据超过 4MB。每个追加操作的请求负载大小最大可为 4MB。

来自REST API documentation :

Append Block uploads a block to the end of an existing append blob.The block of data is immediately available once the call succeeds onthe server. A block may be up to 4 MiB in size.

请以这样的方式分割数据,确保每次调用 AppendBlockAsync 上传的数据不会超过 4MB。

关于c# - 如何将附加 blob 上传到 azure 而不会出现大小限制异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71507739/

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