1 回答
TA贡献1828条经验 获得超6个赞
我解决了我的问题。我必须做两件不同的事情:
首先,我不做数组的副本。相反,对于每个 zip 文件,我只是复制流。这使得 ContentLength 保持在原来的长度。
所做的第二件事是在查看 zip 文件后重置位置。我需要执行此操作,否则上传到 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 关注
- 193 浏览
添加回答
举报