APIM和逻辑应用程序通过REST API读取文件



我是Azure或云世界的新手。我正在尝试使用APIM和逻辑应用程序建立一个宠物项目。我想通过APIM提交一个文件,并使用逻辑应用程序来处理文件内容。我已经在下面为APIM创建了swagger文件。HTTP触发器如何"请求JSON模式"?在我的逻辑应用程序看起来像为了处理这个文件。该文件将是文本/纯文本。任何帮助都太好了。这是swagger定义的一部分。

"paths": {
"/submitEmployeeForm": {
"post": {
"description": "This Operation is used to submit employee files.",
"operationId": "submitEmployee",
"summary": "submitEmployeeDetails",
"responses": {
"200": {
"description": "Accepted",
"schema": {
"$ref": "#/definitions/employeeResponse"
}
},
"400": {
"description": "400 Bad request",
"schema": {
"$ref": "#/definitions/empReqError"
}
},
"401": {
"description":  "Authorization Required"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
},
"500": {
"description": "Internal Server Error"
}          
},
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "transactionId",
"in": "header",
"description": "Unique id to track requests.",
"type": "string",
"format": "uuid",
"required": true
},
{
"in": "formData",
"name": "employeefile",
"description": "upload employee file for processing",
"required": true,
"type": "file"
}
]
}
}
  1. HTTP如何触发"请求体JSON模式"在我的逻辑应用程序看起来像为了处理这个文件?文件格式为text/plain.">

首先,在不指定任何模式的情况下触发你的逻辑应用程序,并在逻辑应用程序运行历史记录中检查逻辑应用程序触发器的输出。

如果你发送一个文件,它看起来像这样:

{
"$content-type": "multipart/form-data; boundary=--------------------------708151345350107134405173",
"$content": "LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTcwODE1MTM0NTM1MDEwNzEzNDQwNTE3Mw0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSIiOyBmaWxlbmFtZT0idGVzdC50eHQiDQpDb250ZW50LVR5cGU6IHRleHQvcGxhaW4NCg0KVGVzdA0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTcwODE1MTM0NTM1MDEwNzEzNDQwNTE3My0tDQo=",
"$multipart": [
{
"headers": {
"Content-Disposition": "form-data; name=""; filename="test.txt"",
"Content-Type": "text/plain"
},
"body": "Test"
}
]
}

复制到剪贴板。

在Logic App设计器中,单击触发器中的Use sample payload to generate schema链接并粘贴复制的JSON。单击"Done"。它将自动生成模式:

{
"type": "object",
"properties": {
"$content-type": {
"type": "string"
},
"$content": {
"type": "string"
},
"$multipart": {
"type": "array",
"items": {
"type": "object",
"properties": {
"headers": {
"type": "object",
"properties": {
"Content-Disposition": {
"type": "string"
},
"Content-Type": {
"type": "string"
}
}
},
"body": {
"type": "string"
}
},
"required": [
"headers",
"body"
]
}
}
}
}
  1. 你真正的问题可能是"我如何在我的逻辑应用程序中处理文件内容?">

要做到这一点,您可以在您的逻辑应用程序操作中使用以下Expression(不是Dynamic content):triggerBody()?['$multipart']?[0]?['body']。由于$multipart是一个数组,因此首先获取它的第一个元素([0]),然后获取body元素的内容(文件内容)。严格地说,您甚至不需要指定Request Body JSON Schema就可以工作。只有在需要使用Dynamic content时才需要模式。

最新更新