question

ShyamalKrishnaShubham-1810 avatar image
0 Votes"
ShyamalKrishnaShubham-1810 asked PramodValavala-MSFT commented

How to limit file size for POST operation on Azure API Management?

The requirement is pretty simple - not to accept incoming req if POST body is more than the permissible size. For eg. If incoming POST body has file of greater than 2 MB.
How can we limit this? Can we add some policy at API level or will it be at subscription level?

azure-api-management
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PramodValavala-MSFT avatar image
0 Votes"
PramodValavala-MSFT answered PramodValavala-MSFT commented

@ShyamalKrishnaShubham-1810 A POST request would have a Content-Length header that you could access via context.Request.Headers.GetValueOrDefault("content-length", 0) and check its value using the choose policy.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PramodValavala-MSFT - Thank you for your response, but when I tried using the policy for validation, I kept getting error as: Error in element 'validate-content' on line 18, column 10: The 'max-size' attribute value must be between 0 and 102400.
One or more fields contain incorrect values:;Error in element 'validate-content' on line 18, column 10: The 'max-size' attribute value must be between 0 and 102400.

Is there anyway we can increase this limit as per our need?

0 Votes 0 ·
PramodValavala-MSFT avatar image PramodValavala-MSFT ShyamalKrishnaShubham-1810 ·

@ShyamalKrishnaShubham-1810 The validate-content policy also checks the same header internally unless the body is compressed. If you don't have to check the compressed payload size, then you could manually check the Content-Length header.

But if you require checking the size of uncompressed payloads and need higher limits, then raising a support ticket for the same is required.


0 Votes 0 ·