This project is read-only.

Upload a file then ZIP it then save to Azure Blob

Apr 3, 2012 at 7:48 AM

My plan is first - Have an FileUploadControl to upload the file, but the uploaded file SHOULD BE SAVE as a Stream.

Then - The uploadedfile (Already a Stream) should be ZIP

Then - The uploadedfile (Already a Stream and already ZIP) should be able to save inside the Blob Storage in Azure.

The code below is somehow working because when i look on the Blob storage, i was able to see the uploaded file and the size of the file has already change (Become smaller)  and it has the zip extension on it, but when i try to get the file and try to manually extract the file, it is corrupted.

// Make a unique blob name
            string extension = System.IO.Path.GetExtension(fileUploadControl.FileName);
            string filenameonly = System.IO.Path.GetFileNameWithoutExtension(fileUploadControl.FileName) + "1";
            string location = System.IO.Path.GetFullPath(fileUploadControl.PostedFile.FileName);
            string fileName = Guid.NewGuid() + extension;

            MemoryStream s = new MemoryStream(fileUploadControl.FileBytes);
            s.Seek(0, SeekOrigin.Begin);

            using (ZipFile zip = new ZipFile())
                ZipEntry ze = zip.AddEntry(filenameonly + ".zip", s);
                Response.ContentType = "application/zip";
                Response.AppendHeader("content-disposition", "attachment; filename=" + filenameonly + ".zip");
            var blob = _BlobContainer.GetBlobReference(filenameonly + ".zip");

            // Set the metadata into the blob
            blob.Metadata["FileName"] = fileUploadControl.FileName;
            blob.Metadata["Submitter"] = submitterBox.Text;

            // Set the properties
            blob.Properties.ContentType = fileUploadControl.PostedFile.ContentType;
Please help me with this.