关于带有Apim和MSI的示例Azure存储Blob CRUD

问题描述

我在Apim仓库中发现了以下示例:https://github.com/Azure/api-management-policy-snippets/blob/master/examples/Authenticate%20using%20Managed%20Identity%20to%20access%20Storage%20Account.xml 有人可以用CRUD和Msi(深度潜水政策)解释一个更好的例子吗?如果我需要处理其他类型的文件(不是json对象)怎么办?将此文件发送到Blob怎么办?我正在尝试从S3获取文件(通过get API)并将其写入Blob存储。 我可以使用发送请求从S3获取数据,否则当我尝试将其发送到Blob存储时会生成错误,因为文件的类型不是纯json对象:

`<send-request mode="new" timeout="20" response-variable-name="blobdata2" ignore-error="false">
        <set-url>https://{{storage}}.blob.core.windows.net/container</set-url>
        <set-method>POST</set-method>
        <set-header name="x-ms-version" exists-action="override">
            <value>2019-07-07</value>
        </set-header>
        <set-header name="x-ms-blob-type" exists-action="override">
            <value>BlockBlob</value>
        </set-header>
        <set-header name="x-ms-type" exists-action="override">
            <value>file</value>
        </set-header>
        <set-body>@($"{((IResponse)context.Variables["blobdata"]).Body.As<JObject>() }")</setbody>
        <authentication-managed-identity resource="https://storage.azure.com" />
    </send-request>`

在这里,我尝试发送“ blobdata ”,因为该变量包含第一个Send-Request中的文件(此处未显示)。我收到的错误如下:

"Expression evaluation Failed. The message body is not a valid JSON. Unexpected character encountered while parsing value: P. Path '',line 0,position 0.\r\n at Newtonsoft.Json.JsonTextReader.ParseValue()\r\n at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader,JsonLoadSettings settings)\r\n at Microsoft.WindowsAzure.apimanagement.Proxy.Gateway.MessageBody.AsJObject(Stream stream,Encoding encoding,JsonSerializerSettings settings)\r\n at Microsoft.WindowsAzure.apimanagement.Proxy.Gateway.MessageBody.As[T](Boolean preserveContent)","Unexpected character encountered while parsing value: P. Path '',position 0."

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)