根据要求,尝试使用 SAS 令牌通过 APIM 将大文件(任何:xml、图像)(超过 100MB)从浏览器上传到私有 azure 存储 blob。我在下面遵循的方法不起作用。我尝试了两种不同的上传选项,该请求在 6 到 7 秒后取消。但是,当我尝试上传成功上传的非常小的文件(如 40 到 70 字节)时。在下方提供 APIM 政策和 javascript 代码。
让我知道我在下面的步骤中做错了什么。
注意:我尝试使用 SAS 令牌通过 APIM 从存储帐户下载大文件 (1GB),该令牌运行良好,没有任何问题。
选项 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>
选项 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>