2

我正在通过 powershell 脚本部署 Web 作业,并且可以设法获取发布凭据,然后在授权标头中添加访问令牌。一切都很好,直到我收到文件大小错误时上传 zip 文件:远程服务器返回错误:(413)请求实体太大。

#Function to get Publishing credentials for the WebApp :
        function Get-PublishingProfileCredentials($resourceGroupName, $AppServiceNameToDeployWebJobs) {

                $resourceType = "Microsoft.Web/sites/config"
                $resourceName = "$AppServiceNameToDeployWebJobs/publishingcredentials"
                $publishingCredentials = Invoke-AzResourceAction -ResourceGroupName $resourceGroupName -ResourceType `
                        $resourceType -ResourceName $resourceName -Action list -ApiVersion $Apiversion -Force
                return $publishingCredentials
        }

        #Pulling authorization access token :
        function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $AppServiceNameToDeployWebJobs) {

                $publishingCredentials = Get-PublishingProfileCredentials $resourceGroupName $AppServiceNameToDeployWebJobs
                return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f `
                                                        $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
        }


        $accessToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $AppServiceNameToDeployWebJobs
        #Generating header to create and publish the Webjob :
        $Header = @{
                'Content-Disposition' = 'attachment; attachment; filename=Copy.zip'
                'Authorization'       = $accessToken
        }
        $apiUrl = "http://xxxx.scm.azurewebsites.net/app_data/jobs/triggered/Test/"
        $result = Invoke-RestMethod -Uri $apiUrl -Headers $Header -Method put `
        -InFile "D:\Work\WebJobs\WebJobsBuild\Test.zip" -ContentType 'application/zip' `
        -TimeoutSec 600 

在此处输入图像描述

zip 文件大小仅为 43MB。如何检查允许的文件大小上限以及如何增加它?我已经尝试过 Invoke-WebRequest 和 Invoke-RestMethod 但结果是一样的

4

1 回答 1

1

我修改$apiUrl它对我有用。

它应该像

$apiUrl = "https://$AppServiceNameToDeployWebJobs.scm.azurewebsites.net/api/triggeredwebjobs/MyWebJob1"

步骤 1. 我在门户中的测试 webjob,MyWebJob1稍后我将创建。

在此处输入图像描述

步骤 2. 在运行 cmd 之前。

在此处输入图像描述

步骤 3. 将 Web 作业名称修改为MyWebJob1

在此处输入图像描述

在此处输入图像描述

步骤 4. 检查门户网站中的网络作业。

在此处输入图像描述

示例代码

    $resourceGroupName='***';
    $AppServiceNameToDeployWebJobs='jas***pp';
    $Apiversion='2019-08-01';

    #Function to get Publishing credentials for the WebApp :
    function Get-PublishingProfileCredentials($resourceGroupName, $AppServiceNameToDeployWebJobs) {

            $resourceType = "Microsoft.Web/sites/config"
            $resourceName = "$AppServiceNameToDeployWebJobs/publishingcredentials"
            $publishingCredentials = Invoke-AzResourceAction -ResourceGroupName $resourceGroupName -ResourceType `
                    $resourceType -ResourceName $resourceName -Action list -ApiVersion $Apiversion -Force
            return $publishingCredentials
    }

    #Pulling authorization access token :
    function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $AppServiceNameToDeployWebJobs) {

            $publishingCredentials = Get-PublishingProfileCredentials $resourceGroupName $AppServiceNameToDeployWebJobs
            return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f `
                                                    $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
    }


    $accessToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $AppServiceNameToDeployWebJobs
    #Generating header to create and publish the Webjob :
    $Header = @{
            'Content-Disposition' = 'attachment; attachment; filename=test.zip'
            'Authorization'       = $accessToken
    }
    $apiUrl = "https://$AppServiceNameToDeployWebJobs.scm.azurewebsites.net/api/triggeredwebjobs/MyWebJob1" 
    $result = Invoke-RestMethod -Uri $apiUrl -Headers $Header -Method put `
    -InFile "E:\test.zip" -ContentType 'application/zip' `
    -TimeoutSec 600
于 2020-12-08T05:11:54.060 回答