1 回答

TA貢獻(xiàn)1828條經(jīng)驗 獲得超6個贊
我解決了我的問題。我必須做兩件不同的事情:
首先,我不做數(shù)組的副本。相反,對于每個 zip 文件,我只是復(fù)制流。這使得 ContentLength 保持在原來的長度。
所做的第二件事是在查看 zip 文件后重置位置。我需要執(zhí)行此操作,否則上傳到 Azure Blob 存儲的 zip 文件將為空。
private static bool CanUploadBatchOfFiles(HttpPostedFileBase[] files)
{
foreach (var file in files)
{
if (file.FileName.EndsWith(".zip"))
{
// Part one of the solution
Stream fileCopy = new MemoryStream();
file.InputStream.CopyTo(fileCopy);
using (ZipArchive zipFile = new ZipArchive(fileCopy))
{
foreach (ZipArchiveEntry entry in zipFile.Entries)
{
// Code left out
}
}
// Part two of the solution
file.InputStream.Position = 0;
}
}
return true;
}
- 1 回答
- 0 關(guān)注
- 213 瀏覽
添加回答
舉報