logo
Tags down

shadow

How to prevent large file POST requests using Azure APIM?


By : user6111778
Date : August 01 2020, 08:00 AM
it should still fix some issue You can apply the following policy for all your APIs. For each POST request, the policy will check the body size, and if the size is above 50MB, it will return status 413 - Payload Too Large.
code :
<policies>
    <inbound>
        <base />
        <choose>
            <when condition="@(context.Request.Method == "POST")">
                <set-variable name="bodySize" value="@(context.Request.Headers["Content-Length"][0])" />
                <choose>
                    <when condition="@(int.Parse(context.Variables.GetValueOrDefault<string>("bodySize"))<52428800)">
                        <!--let it pass through by doing nothing-->
                    </when>
                    <otherwise>
                        <return-response>
                            <set-status code="413" reason="Payload Too Large" />
                            <set-body>@{
                                    return "Maximum allowed size for the POST requests is 52428800 bytes (50 MB). This request has size of "+ context.Variables.GetValueOrDefault<string>("bodySize") +" bytes";
                                } 
                            </set-body>
                        </return-response>
                    </otherwise>
                </choose>
            </when>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>


Share : facebook icon twitter icon

Why would large POST requests not reach my Azure web role?


By : endastory
Date : March 29 2020, 07:55 AM
wish helps you After much effort put into the investigation and a support request the conclusion is that there's some software outside Azure that emits that message perhaps some proxy server or something.
Our service was configured with and this is known to cause IIS return HTTP 500 and close the connection for requests with lengths in certain range. It's just a guess but perhaps that other software would intercept the HTTP 500 response and emit the "Hello," message.

python:requests, how do I post MULTIPART/FORM-DATA and stream large file?


By : Gladyswilliams
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Requests does not actually stream multipart/form-data uploads (but it will be landing there soon). Until then, install requests-toolbelt from PyPI. To use it, your script would look like
code :
import requests
import json
from requests_toolbelt.multipart import encoder


payload = {
    "operating_mode":"accurate",
    "model":{
       "name":"code"
    },
    "channels":{
        "first":{
            "format": "audio_format",
            "result_format": "lattice"
         }
     }
}

multiple_files = [
    ("json", "application/json", json.dumps(payload)),
    ("first", "audio/wave", open("c.wav", "rb"),
]
multipart_encoder = encoder.MultipartEncoder(
    fields=multiple_files,
    boundary="xxx---------------xxx",
)
r = requests.post("http://localhost:8080",
                  data=multipart_encoder,
                  headers={'Content-Type': multipart_encoder.content_type})

Azure APIM - How can I Request/POST. I want to block certain characters and allow few?


By : Flack
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Azure APIM - How can I Request/POST. I want to block certain characters and allow few in incoming POST? , You can use multiline syntax for more complex logic:
code :
<set-body>@{
    var body = context.Request.Body.As<string>(preserveContent: true);
    body = body.Replace("'", string.Empty);
    return body;
}</set-body>

How to prevent Ocp-Apim-Trace: true and ocp-apim-trace-location in production?


By : BHARANI DHARAN
Date : March 29 2020, 07:55 AM
Hope that helps Trace location (ocp-apim-trace-location in response header) is available only for admin accounts. For non-admin accounts or when there is no subscription key the traces aren't collected.

'requests.post' Files Upload Large File: (More than ~1.5 MB): Python


By : prem g
Date : March 29 2020, 07:55 AM
Hope this helps Here I'm trying to use requests.post for file upload. , This works fairly well for me (Python3 with requests):
shadow
Privacy Policy - Terms - Contact Us © voile276.org