【发布时间】:2020-12-03 13:01:02
【问题描述】:
我正在通过 powershell 脚本部署 Web 作业,并且可以设法获取发布凭据,然后在授权标头中添加访问令牌。在我收到文件大小错误时上传 zip 文件之前一切都很好:远程服务器返回错误:(413) Request Entity Too Large.
#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
压缩文件大小仅为 43MB。如何检查允许的文件大小上限以及如何增加它?我已经尝试过 Invoke-WebRequest 和 Invoke-RestMethod 但结果是一样的
【问题讨论】:
-
查看您的屏幕截图,响应似乎来自 Azure AD (login.microsoftonline.com),所以我会先检查身份验证部分。
-
经过各种尝试,终于发现
$apiUrl错了。我已经测试过了,把修改后的代码贴在了底部。 -
我的webjob发布文件是
72.4M,一切正常,所以问题不在于文件大小有限。查了一些博客,文件限制在110M左右,没有测试。有兴趣的可以研究一下。
标签: azure powershell azure-webjobs invoke-restmethod