使用C#中的azure函数解压密码文件

问题描述

我正在尝试在 blob 存储中解压缩受密码保护的文件。使用带有 C# 编码和 winrar.exe 的 azure 函数解压.. 我无法解压缩文件.. 收到“未找到存档”警告..​​

我正在传递类似 winrar.exe x -p{pwd} http://....//file.zip{input BLOB FILE uri} http://...//output//{ 的参数输出 blob 容器 uri}

请帮助上面的参数是否正常或需要更改以获取输入的 blob 文件位置..

我的代码

            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;
          }

有没有可能得到这样的 blob 路径 D:/home/site/..??

解决方法

如果您想解压缩 Azure 函数存储在 Azure blob 存储中的 .zip 文件,只需尝试下面的代码片段:

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

在这个演示中,我使用了 Ionic.Zip。 我已经在我这边进行了测试,它非常适合我:

enter image description here

如果您还有其他问题,请告诉我。

更新:

在 Azure 函数中创建临时路径:

enter image description here