-1

I am trying to unzip password protected file in blob storage. Using azure function with C# coding and winrar.exe to unzip.. I am not able to unzip the files.. Getting "No archive found" Warning..

I am Passing the argument like winrar.exe x -p{pwd} http://....//file.zip{input BLOB FILE uri} http://...//output//{output blob container uri}

Please help whether the above argument are fine or need to chg to get the input blob file location..

mycode:

            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;
            startInfo.UseShellExecute = false;
            startInfo.WorkingDirectory = uri.AbsoluteUri;
            startInfo.FileName = "Winrar.exe";
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardInput = true;
            startInfo.Arguments = "winrar.exe x -p" + pwd + " -ibck " + inputBlob.Uri.ToString()+ " " + outBlob.Container.Uri.ToString() + "/";
            try
           {
             // Start the process with the info we specified.
            // Call WaitForExit and then the using statement will close.
           using (Process exeProcess = Process.Start(startInfo))
           {
             exeProcess.WaitForExit();
            }
            }
           catch (Exception esf)
          {
             string msd = esf.Message;
          }

Is it possible to get the blob path like this D:/home/site/..??

Sree
  • 33
  • 1
  • 7

1 Answers1

0

If you want to unzip a .zip file that stored in Azure blob storage by Azure function, just try code snippy below:

            var tempPath = "d:/home/temp/";
            var zipBlobName = "";
            var containerName = "";
            var password = "123456";
            var storageConnString = "";
            var tempFilePath = tempPath + zipBlobName;
            var zipDestPath = tempPath + "unzip";

            //download zip to local as a temp file
            var blobClient = new BlobServiceClient(storageConnString).GetBlobContainerClient(containerName).GetBlobClient(zipBlobName);
            blobClient.DownloadTo(tempFilePath);

            //unzip file to a folder 
            ZipFile zip = ZipFile.Read(tempFilePath);
            zip.Password = password;
            Directory.CreateDirectory(zipDestPath);
            foreach (ZipEntry e in zip)
            {
               e.Extract(zipDestPath, ExtractExistingFileAction.OverwriteSilently);
            }
            zip.Dispose();

            //remove temp zip file
            File.Delete(tempFilePath);

In this demo, I am using Ionic.Zip. I have tested on my side and it works perfectly for me:

enter image description here

Let me know if you have any more questions.

UPDATE:

Create temp path in Azure function:

enter image description here

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Thanks for your reply. I have doubt on the temp path given. Is that temp path will remain same on portal? in that case how to remove those files. – Sree Jun 04 '21 at 07:21
  • @Sree, You need to create the path on Azure function by command: `mkdir` by kudu , I have appended the capture in my answer. And you can remove files by code `File.Delete(tempFilePath);`: the last line of my code – Stanley Gong Jun 04 '21 at 07:29
  • will this solution is suitable for larger file size about 30gb. will they affect the performance ? Also is it possible to run .exe files in Azure functions? – Sree Jun 04 '21 at 07:55
  • @Sree, If your file size exceeds 30GB, I am afraid you need to download the .zip file in chunk , details see this doc : https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-scalable-app-download-files?tabs=dotnet , it is possible to run .exe file in Azure function if you want to do so, this post could be helpful: https://stackoverflow.com/questions/45348498/run-exe-executable-file-in-azure-function – Stanley Gong Jun 04 '21 at 08:28
  • @Sree How's going? Has your issue got resolved? – Stanley Gong Jun 07 '21 at 01:07
  • Yeah. I can able to unzip files. But not this way.. I have downloaded the blob data to stream.. And then after unzipped uploaded the files to blob storage.. Because i am not able to access the path specified.. Any how thanks @stanley gong for ur support – Sree Jun 08 '21 at 14:28