在Windows Azure中的错误时,上传一个zip文件:在头“被抛出:ZipException未处理”,“EOF”
-
23-09-2019 - |
题
我一直在使用Windows Azure中创建一个文档管理系统,到目前为止,事情已经过去了好。我已经通过一个asp.net前端已经能够上传和下载文件到BLOB存储。
什么我试图现在要做的就是允许用户上传一个.zip文件,然后把文件指出,.zip文件,并将其保存为单个文件。问题是,我得到“被抛出:ZipException未处理”,“EOF在头”,我不知道为什么。
我用我已经用于许多其它任务,其工作很大的ICSharpCode.SharpZipLib库。
下面是基本的代码:
CloudBlob ZipFile = container.GetBlobReference(blobURI);
MemoryStream MemStream = new MemoryStream();
ZipFile.DownloadToStream(MemStream);
....
while ((theEntry = zipInput.GetNextEntry()) != null)
和它的上线,与而我得到的错误开始。我加了10秒的睡眠时间,只是为了确保有足够的时间过去了。
MemStream具有如果我调试它的长度,但有时zipInput的做法,但并非总是如此。它总是失败。
解决方案
只是一个随机的猜测,但你需要寻求流回到0您阅读过吗?不知道你这样做已经(或者,如果有必要)。
其他提示
@Smarx暗示的伎俩对我来说太。避免拉链内空文件,关键是要位置设置为零。为了清楚起见这里的是,发送含有天青团块到浏览器拉链流的样本代码。
var fs1 = new MemoryStream();
Container.GetBlobReference(blobUri).DownloadToStream(fs1);
fs1.Position = 0;
var outputMemStream = new MemoryStream();
var zipStream = new ZipOutputStream(outputMemStream);
var entry1 = new ZipEntry(fileName);
zipStream.PutNextEntry(entry1);
StreamUtils.Copy(fs1, zipStream, new byte[4096]);
zipStream.CloseEntry();
zipStream.IsStreamOwner = false; // False stops the Close also Closing the underlying stream.
zipStream.Close(); // Must finish the ZipOutputStream before using outputMemStream.
outputMemStream.Position = 0;
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + zipFileName);
Response.OutputStream.Write(outputMemStream.ToArray(), 0, outputMemStream.ToArray().Length);
Response.End();
不隶属于 StackOverflow