none
Unzipping file in Azure Blob Storage - Path format not supported

    Question

  • Hi,

    I am looking at unzipping a file Azure. I am using the IonicZip library to do so

    This is my function:

            public void UploadZip()
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["SN_SAPPHIRE"]);
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container = blobClient.GetContainerReference("zipfile");

                using (ZipFile zip = ZipFile.Read(fileUpload1.PostedFile.InputStream))
                {
                    foreach (ZipEntry e in zip)
                    {
                        e.Extract(container.Uri.ToString());
                    }
                }
            }

    However, it looks like the path that I am using to save the extracted files is not correct:

    container.Uri.ToString());

    This is the error that I am getting:

    An exception of type 'System.NotSupportedException' occurred in Ionic.Zip.dll but was not handled in user code

    Additional information: The given path's format is not supported.

    Could you please let me know what to use instead of the container uri.

    Thank you for your help.

    Anne

    Thursday, September 29, 2016 11:32 PM

All replies

  • Hi,

    Thank you for posting here!

    We are checking on the query and would get back to you soon on this.

    apologise for the inconvenience and appreciate your time and patience in this matter.

    In the meantime, kindly check the below mentioned link which may help your query:

     

    https://code.msdn.microsoft.com/How-to-unzip-files-to-53234a56

     

    Regards,

    Vikranth S.

    Friday, September 30, 2016 3:34 PM
    Moderator
  • You're not actually doing any upload here. You'll need to extract the data to something (a stream or a local file) and then create CloudBlobContainer object and from that, a CloudBlockBlob object that you call one of the UploadFrom* methods on. Please take a look at our Getting Started and see if that helps.
    Friday, September 30, 2016 5:22 PM
  • This is what I've done and it works, but I'm not sure it is the best solution.

    I am extracting the files in ~/App_Data/Zip/, then load them into Azure, and remove them from the directory. 

    I was thinking of using Azure Local storage, but from what I understand I need to have a VM, which I don't have. My application, database and storage are directly int Azure.


            protected void btnExtract_Click(object sender, EventArgs e)
            {
    	    if (fileUpload1.HasFile)
                {
                    DTO.BlobUpload b = new DTO.BlobUpload();
    
                    b.FileName = Path.GetFileName(fileUpload1.PostedFile.FileName);
                    b.Stream = fileUpload1.PostedFile.InputStream;
    
                    string location = Server.MapPath("~/App_Data/Zip/");
    
                    Ionic.Zip.ZipFile fileToExtract = Ionic.Zip.ZipFile.Read(b.Stream);
                    fileToExtract.ExtractAll(location, ExtractExistingFileAction.OverwriteSilently);
    
                    string[] fileEntries = Directory.GetFiles(location);
                    foreach (string fileName in fileEntries)
                    {
                        b.FileName=Path.GetFileName(fileName);
                        b.FileExt = Path.GetExtension(fileName);
                        b.LastModified = File.GetCreationTime(fileName);
                        b.Stream = File.Create(location + b.FileName);
                        b.UpdatedBy= NVar.UserName;
                        BLL.BlobStorage.UploadZip(b);
                        File.Delete(location + b.FileName);
                    }
    	}
    
            public static void UploadZip(DTO.BlobUpload b)
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["SN_SAPPHIRE"]);
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container = blobClient.GetContainerReference("zipfile");
    
                CloudBlockBlob blockBlob = container.GetBlockBlobReference(b.FileName);
    
                using (b.Stream)
                {
                    blockBlob.UploadFromStream(b.Stream);
                }
            }


    Tuesday, October 4, 2016 9:19 PM