2

I am deploying a web job through powershell script and can manage to get the publishing credentials and then add the access token in the authorization header. All is fine until it uploads the zip file when I receive file size error: The remote server returned an error: (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 

enter image description here

The zip file size is only 43MB. How can I check the upper limit of file size allowed and how can I increase it? I've tried both Invoke-WebRequest and Invoke-RestMethod but the result is the same

man_luck
  • 1,605
  • 2
  • 20
  • 39
  • Looking at your screenshot, the response seems to come from Azure AD (login.microsoftonline.com) so i would check the authentication part first. – evilSnobu Dec 03 '20 at 13:29
  • After various attempts, I finally found that `$apiUrl` was wrong. I have tested it and posted the modified code at the bottom. – Jason Pan Dec 08 '20 at 05:18
  • My webjob release file is `72.4M`, everything is normal, so the problem is not that the file size is limited. Check some blogs that the file limit is about `110M`, and it has not been tested. If you are interested, you can research. – Jason Pan Dec 08 '20 at 05:22

1 Answers1

1

I modify $apiUrl and it works for me.

It should be like

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

Step 1. My test webjob in portal, and I will create MyWebJob1 later.

enter image description here

Step 2. Before running cmd.

enter image description here

Step 3. Modify the web job name as MyWebJob1.

enter image description here

enter image description here

Step 4. Check the webjob in portal.

enter image description here

Sample Code

    $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
Jason Pan
  • 15,263
  • 1
  • 14
  • 29