0

As per the requirement, trying to upload large file (any: xml, images) (more than 100MB) from browser to private azure storage blob via APIM using SAS Token. The methods which I followed below not working. I tried TWO different options of upload, which request has cancelled after 6 to 7 seconds. However, when I tried to upload very small files (like 40 to 70Bytes) which uploaded successfully. Providing the APIM policies and javascript code below.

Let me know what I'm making wrong over here in below steps.

Note: I tried download the large file (1GB) from storage account via APIM using SAS token which works perfectly without any issue.

Option 1:

<policies>
    <inbound>
        <base />
        <set-method>PUT</set-method>
        <set-header name="x-ms-blob-type" exists-action="override">
            <value>BlockBlob</value>
        </set-header>
        <set-header name="x-ms-version" exists-action="override">
            <value>2020-02-10</value>
        </set-header>
        <set-header name="Authorization" exists-action="delete" />
        <set-backend-service base-url="https://{{storageAccountName}}.blob.core.windows.net/test/test.xml?{{SASToken}}" />
        <rewrite-uri template="?" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

Option 2:

<policies>
    <inbound>
        <base />
        <set-variable name="storageAccount" value="{{storageAccountName}}" />
        <send-request mode="new" response-variable-name="blobdata" ignore-error="true" fail-on-error-status-code="true">
            <set-url>@{return string.Format("https://{0}.blob.core.windows.net/test/test.xml?{{SASToken}}",(string)context.Variables["storageAccount"]);}</set-url>
            <set-method>PUT</set-method>
            <set-header name="x-ms-blob-content-type" exists-action="override">
                <value>application/xml</value>
            </set-header>
            <set-header name="x-ms-blob-type" exists-action="override">
                <value>BlockBlob</value>
            </set-header>
            <set-header name="x-ms-version" exists-action="override">
                <value>2020-02-10</value>
            </set-header>
            <set-header name="Authorization" exists-action="delete" />
            <set-body>@( context.Request.Body.As<string>() )</set-body>
        </send-request>
        <return-response>
            <set-status code="200" reason="OK" />
            <set-body>@($"{((IResponse)context.Variables["blobdata"]).Body.As<string>() }")</set-body>
        </return-response>
    </inbound>
    <backend>
       <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
Satheesh Natarajan
  • 459
  • 2
  • 7
  • 31
  • Why dont you upload file directly to blob using SAS token ? – Vova Bilyachat Mar 30 '21 at 13:21
  • @VovaBilyachat the requirement is to upload files into private storage account – Satheesh Natarajan Mar 30 '21 at 13:24
  • What error do you get when you upload large files? – Vova Bilyachat Mar 30 '21 at 13:38
  • based on the application insight, APIM forward the request to storage account and storage account return the empty response with response status code as 0 (within a second) – Satheesh Natarajan Mar 30 '21 at 14:00
  • Second option likely will not work as it requires buffering whole request body into memory, depending on payload size that may not be possible. 0 status code indicates lack of backend response, so request processing error may have taken place. Try to repro the problem using API inspector: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-api-inspector to get trace for the call – Vitaliy Kurokhtin Mar 31 '21 at 02:25
  • To use API inspector you not necessary need to use Azure Portal. Just add an extra header to your request: Ocp-Apim-Trace: and response from APIM should contain Ocp-Apim-Trace-Location header with trace details – Vitaliy Kurokhtin Mar 31 '21 at 02:26
  • We restricted payloads over 40MB on our API Management instances as we observed, that transfers with higher volumes will not be transferred reliably at all times - with one HTTP request. In the end this is not a file transfer system. – Kai Walter Mar 31 '21 at 05:30
  • @KaiWalter Thanks for the update. I tried with 23MB file with removed forward-request-timeout which also failed. – Satheesh Natarajan Mar 31 '21 at 07:05

0 Answers0