gpt4 book ai didi

azure - 从 azure Storage c# 下载 Zip 文件

转载 作者:行者123 更新时间:2023-12-03 02:38:56 25 4
gpt4 key购买 nike

我正在循环访问数据库中的文件名以及 azure 存储中的同一文件。我正在压缩这 n 个文件并从 azure 存储下载。我将压缩文件保存到本地存储中。当我解压并想要查看文件时,它说已损坏/损坏。

public ActionResult Download(string productid, string YearActiveid)
{
HomePageModel homepagemodel = new HomePageModel();

homepagemodel.ProdHeaderDetail = GetProductHeaderDetail(productid, YearActiveid);
homepagemodel.PriorYearsActive = GetPriorYearActive(productid, YearActiveid);

CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=<name>;AccountKey=<key>;EndpointSuffix=core.windows.net");
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("product");

var blobFileNames = new string[] { "file1.png", "file2.png", "file3.png", "file4.png" };
var outputMemStream = new MemoryStream();
var zipOutputStream = new ZipOutputStream(outputMemStream);
foreach (var ProdHeaderDetail in homepagemodel.ProdHeaderDetail)
{
zipOutputStream.SetLevel(5);
var blob = cloudBlobContainer.GetBlockBlobReference(ProdHeaderDetail.FileName);
var entry = new ZipEntry(ProdHeaderDetail.FileName);
zipOutputStream.PutNextEntry(entry);
blob.DownloadToStreamAsync(zipOutputStream);
}


zipOutputStream.Finish();
//zipOutputStream.Close();
//zipOutputStream.CloseEntry();
zipOutputStream.IsStreamOwner = false;
outputMemStream.Position = 0;
return File(outputMemStream, "application/zip", "filename.zip");

}

最佳答案

我通过添加异步和等待解决了该问题

公共(public)异步任务下载(字符串productid,字符串YearActiveid)

等待 blob.DownloadToStreamAsync(zipOutputStream);

关于azure - 从 azure Storage c# 下载 Zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62176614/

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