使用C#解压缩上传到Azure Web Apps的文件

时间:2015-04-20 13:24:28

标签: c# azure azure-web-sites

我的问题非常类似于Unzip file uploaded to Azure Websites - 我需要解压缩远程服务器上的zip文件。不同之处在于我需要使用C#代码完成此任务。有可能吗?

1 个答案:

答案 0 :(得分:3)

可以使用此API https://github.com/projectkudu/kudu/wiki/REST-API#zip。该API实际上为您提供了zip文件上传和提取功能。

感谢Suwat Ch和他在这里的答案https://social.msdn.microsoft.com/Forums/azure/en-US/7fb2deed-6d1e-4529-9249-f67c83f373af/unzip-file-uploaded-to-azure-web-apps-using-c?forum=windowsazurewebsitespreview#7fb2deed-6d1e-4529-9249-f67c83f373af我设法让它发挥作用:



public void UploadZipToAzure()
        {
            byte[] projectFile = File.ReadAllBytes(@"C:\YourZipFile.zip");

            String Url = "https://YourAzureWebAppName.scm.azurewebsites.net/api/zip/site/wwwroot/";
            WebRequest request = WebRequest.Create(Url);

            request.ContentType = "application/x-zip-compressed";
            request.Method = "PUT";
            //Your Azure FTP deployment credentials here
            request.Credentials = new NetworkCredential("UserName - Azure's FTP deployment server name", "Password - Azure's FTP deployment server password");

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(projectFile, 0, projectFile.Length);
            requestStream.Close();

            WebResponse response = request.GetResponse();
        }