English 中文(简体)
Error in Windows Azure when uploading a zip file: "ZipException was unhandled" "EOF in header"
原标题:

I ve been using Windows Azure to create a document management system, and things have gone well so far. I ve been able to upload and download files to the BLOB storage through an asp.net front end.

What I m attempting to do now is allow users to upload a .zip file, and then take the files out of that .zip and save them as individual files. Problem is, I m getting "ZipException was unhandled" "EOF in header" and I don t know why.

I m using the ICSharpCode.SharpZipLib library which I ve used for many other tasks and its worked great.

Here s the basic code:

CloudBlob ZipFile = container.GetBlobReference(blobURI);
MemoryStream MemStream = new MemoryStream();
ZipFile.DownloadToStream(MemStream);
....
while ((theEntry = zipInput.GetNextEntry()) != null)

and it s on the line that starts with while that I get the error. I added a sleep duration of 10 seconds just to make sure enough time had gone by.

MemStream has a length if I debug it, but the zipInput does sometimes, but not always. It always fails.

最佳回答

Just a random guess, but do you need to seek the stream back to 0 before you read it? Not sure if you re doing that already (or if it s necessary).

问题回答

@Smarx hint did the trick for me too. The key to avoiding empty files inside the zip is to set the position to zero. For the sake of clarity here is sample code that sends a zip-stream containing an Azure blob to the browser.

        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();




相关问题
Windows Azure WorkerRole response

I am working on an Azure demo to run Powershell in a worker role. In my web role I add the name of the Powershell script which is to be run to a CloudQueue object. I can print the script output to ...

Windows Azure WebRole stuck in a deployment loop

I ve been struggling with this one for a couple of days now. My current Windows Azure WebRole is stuck in a loop where the status keeps changing between Initializing, Busy, Stopping and Stopped. It ...

Getting a token for Windows Azure

We are looking at Windows Azure, but getting a token appears to be hard now, at least that s what I m seeing in web searches. Anyone tried it or know how to accelerate that process? Any idea how long ...

Developing Azure .Net 4.0 Applications

Presently .Net 4.0 is not supported on Azure. This thread indicates that you will not be able to use .Net 4.0 with VS 2010 until it is supported in the cloud. http://social.msdn.microsoft.com I d ...

.NET 4.0 on Windows Azure?

My google-fu is failing me on this one. As a possible solution to Unit Testing .NET 3.5 projects using MStest in VS2010 (but I ve put this in a seperate question because it s kind of unrelated): Is ...

热门标签