【问题标题】:How to parse content of BLOB-file in Azure Logic App如何在 Azure Logic App 中解析 BLOB 文件的内容
【发布时间】:2019-08-31 20:45:18
【问题描述】:

我正在开发一个 Azure 逻辑应用程序,每次将 JSON 文件添加到 BLOB 存储时都会触发该应用程序。 JSON 文件包含一个 CustomerId,并且基于此 Id,我想使用 HTTP 请求将 JSON 文件的内容发送到不同的端点。

我的 Azure Logic App 目前看起来像这样;

整个上午我一直在研究和尝试很多事情,但我无法理解这一点。我尝试过类似的东西;

json(body('Get_blob_content_using_path'))

decodeBase64(body('Get_blob_content_using_path'))

只是默认选项,如屏幕截图中可见。但我无法弄清楚如何做到这一点。我想要的只是根据 CustomerId 向左或向右移动。

为了清楚起见。问题在于逻辑应用的条件步骤。我可以从存储中检索 BLOB 文件,但问题在于从 JSON 中解析 CustomerId,以便我可以在条件内对其进行验证。有人知道我该如何解决这个问题吗?

【问题讨论】:

  • 为了清楚起见,问题是检索内容还是从您成功检索的内容中获取值?
  • @Johns-305 好问题!我会更新这个话题,希望能更清楚一些。问题在于解析条件内的 JSON,以便我可以检查它。那是在检索内容之后。

标签: azure azure-logic-apps


【解决方案1】:

最后,我能够通过在条件之前和之后添加 compose 步骤来解决问题,这将使我获得 BLOB 文件的内容。 compose get 是 blob 文件的内容,然后我可以根据我想要的 CustomerId 对其进行验证。 This 主题让我找到了解决方案的正确方向。

更新:

最终的逻辑应用如下所示;

以以下逻辑应用代码开始创建;

{
    "$connections": {
        "value": {
            "azureblob": {
                "connectionId": "<snip>",
                "connectionName": "azureblob",
                "id": "<snip>"
            },
            "slack": {
                "connectionId": "<snip>",
                "connectionName": "slack",
                "id": "<snip>"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@base64ToString(body('Get_blob_content').$content)",
                "runAfter": {
                    "Get_blob_content": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Condition_2": {
                "actions": {
                    "Condition_3": {
                        "actions": {
                            "Delete_blob_3": {
                                "inputs": {
                                    "host": {
                                        "connection": {
                                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                                        }
                                    },
                                    "method": "delete",
                                    "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                },
                                "runAfter": {},
                                "type": "ApiConnection"
                            }
                        },
                        "else": {
                            "actions": {
                                "Copy_blob_2": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/datasets/default/copyFile",
                                        "queries": {
                                            "destination": "/<some-blob-container>/@{triggerBody()?['Name']}",
                                            "overwrite": false,
                                            "queryParametersSingleEncoded": true,
                                            "source": "@triggerBody()?['Path']"
                                        }
                                    },
                                    "runAfter": {
                                        "Post_message_2": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "ApiConnection"
                                },
                                "Delete_blob_4": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                                            }
                                        },
                                        "method": "delete",
                                        "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                    },
                                    "runAfter": {
                                        "Copy_blob_2": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "ApiConnection"
                                },
                                "Post_message_2": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['slack']['connectionId']"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/chat.postMessage",
                                        "queries": {
                                            "channel": "<snip>",
                                            "text": "<some-message>"
                                        }
                                    },
                                    "runAfter": {},
                                    "type": "ApiConnection"
                                }
                            }
                        },
                        "expression": {
                            "or": [
                                {
                                    "equals": [
                                        "@outputs('HTTP_2')['statusCode']",
                                        200
                                    ]
                                },
                                {
                                    "equals": [
                                        "@outputs('HTTP_2')['statusCode']",
                                        202
                                    ]
                                }
                            ]
                        },
                        "runAfter": {
                            "HTTP_2": [
                                "Succeeded",
                                "Failed"
                            ]
                        },
                        "type": "If"
                    },
                    "HTTP_2": {
                        "inputs": {
                            "authentication": {
                                "password": "<some-password>",
                                "type": "Basic",
                                "username": "<some-username>"
                            },
                            "body": "@outputs('Compose')",
                            "headers": {
                                "Content-Type": "application/json"
                            },
                            "method": "POST",
                            "uri": "<some-url>"
                        },
                        "runAfter": {},
                        "type": "Http"
                    }
                },
                "else": {
                    "actions": {
                        "Condition_4": {
                            "actions": {
                                "Delete_blob_5": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                                            }
                                        },
                                        "method": "delete",
                                        "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                    },
                                    "runAfter": {},
                                    "type": "ApiConnection"
                                }
                            },
                            "else": {
                                "actions": {
                                    "Copy_blob_3": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                                }
                                            },
                                            "method": "post",
                                            "path": "/datasets/default/copyFile",
                                            "queries": {
                                                "destination": "/<some-blob-container>/@{triggerBody()?['Name']}",
                                                "overwrite": false,
                                                "queryParametersSingleEncoded": true,
                                                "source": "@triggerBody()?['Path']"
                                            }
                                        },
                                        "runAfter": {
                                            "Post_message_3": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "ApiConnection"
                                    },
                                    "Delete_blob_6": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                                }
                                            },
                                            "method": "delete",
                                            "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                        },
                                        "runAfter": {
                                            "Copy_blob_3": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "ApiConnection"
                                    },
                                    "Post_message_3": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['slack']['connectionId']"
                                                }
                                            },
                                            "method": "post",
                                            "path": "/chat.postMessage",
                                            "queries": {
                                                "channel": "<snip>",
                                                "text": "<some-message>"
                                            }
                                        },
                                        "runAfter": {},
                                        "type": "ApiConnection"
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@outputs('HTTP_3')['statusCode']",
                                            200
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@outputs('HTTP_3')['statusCode']",
                                            202
                                        ]
                                    }
                                ]
                            },
                            "runAfter": {
                                "HTTP_3": [
                                    "Succeeded"
                                ]
                            },
                            "type": "If"
                        },
                        "HTTP_3": {
                            "inputs": {
                                "authentication": {
                                    "password": "<some-password>",
                                    "type": "Basic",
                                    "username": "<some-username>"
                                },
                                "body": "@outputs('Compose')",
                                "headers": {
                                    "Content-Type": "application/json"
                                },
                                "method": "POST",
                                "uri": "<some-url>"
                            },
                            "runAfter": {},
                            "type": "Http"
                        }
                    }
                },
                "expression": {
                    "and": [
                        {
                            "contains": [
                                "@outputs('Compose')",
                                "\"CustomerId\":\"00000000-0000-0000-0000-000000000000\""
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Get_blob_content": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Path']))}/content",
                    "queries": {
                        "inferContentType": true
                    }
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_blob_is_added_or_modified_(properties_only)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/triggers/batch/onupdatedfile",
                    "queries": {
                        "folderId": "<some-generated-folderid>",
                        "maxFileCount": 100
                    }
                },
                "metadata": {
                    "<some-generated-folderid>": "/<some-blob-container>"
                },
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 1
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnection"
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 2021-07-15
    • 2019-06-05
    • 2022-01-11
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多