Error loading Windows Azure DownloadOptream EOF

I use Windows Azure to create a document management system, and so far everything went well. I was able to upload and upload files to the BLOB repository through the asp.net interface.

What I'm trying to do now is let users download a zip file and then extract the files from this .zip and save them as separate files. The problem is that I get "ZipException was unhandled" "EOF in the header", and I don't know why.

I use the ICSharpCode.SharpZipLib library, which I used for many other tasks, and it worked great.

Here is the basic code:

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

and it starts with a line when I get an error. I added a sleep duration of 10 seconds to make sure enough time has passed.

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

Thanks for any help.

Dave

+3
source share
2 answers

Just a random guess, but do you need to look for a stream to 0 before you read it? Not sure if you are already doing this (or if necessary).

+2
source
The @Smarx tip also did for me. The key to avoiding empty files inside zip is setting the position to zero. For clarity, here is a sample code that sends a zip stream containing the Azure blade 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();
0
source

Source: https://habr.com/ru/post/1739184/


All Articles