【发布时间】:2021-03-03 11:25:03
【问题描述】:
我目前有以下代码,它使用 SAS URI 从 blob 下载 zip 文件,解压缩并将内容上传到新容器
var response = await new BlobClient(new Uri(sasUri)).DownloadAsync();
using (ZipArchive archive = new ZipArchive(response.Value.Content))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
BlobClient blobClient = _blobServiceClient.GetBlobContainerClient(containerName).GetBlobClient(entry.FullName);
using (var fileStream = entry.Open())
{
await blobClient.UploadAsync(fileStream, true);
}
}
}
我的代码因“流太长”异常而失败:System.IO.IOException:流太长。在 System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) 在 System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize) 在 System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode模式,布尔值 leaveOpen).
我的 zip 文件大小为 9G。解决此异常的更好方法是什么?我想避免将任何文件写入磁盘。
【问题讨论】:
-
这个框架还是核心?
-
是点网核心
-
我不熟悉 Azure API,
DownloadAsync是否会将整个内容下载到内存中,或者它会返回一个流并在下载内容时对其进行处理?也许 ZipArchive 可以在流上工作而无需将整个内容下载到内存中? -
你弄明白了吗?
-
@Tarostar 发布解决方案
标签: c# .net .net-core azure-blob-storage ziparchive