0
votes

I have to pass File Name and File content to Azure function when new file is added or modified in SFTP folder. I am able to pass them but File content is getting passed as complex type json as follows:

{
  "fileContent": {
    "$content-type": "application/octet-stream",
    "$content": "QWxvZnQgQidoYW0gU29obyBTcSAgICAg=="
  },
  "fileName": "testFile"
}

I just need to pass $content to Azure Function. My current code is as follows in logic app

"body": {
                            "fileContent": "@triggerBody()",
                            "fileName": "@triggerOutputs()['headers']['x-ms-file-name']"
                        },

How could I pass only content form FileContent to Azure function?

2

2 Answers

3
votes

You should be able to just pass the content as-is. Logic Apps would decode the data and pass it as binary to the azure function (assuming the function can accept the binary content). You can pass the file name as a header.

If you want to attach the content as a property on a object, then you can use

"body": {
  "fileContent": "@base64(triggerBody())",
  "fileName": "@triggerOutputs()['headers']['x-ms-file-name']"
}
1
votes

As you can see, you are getting a $content property, so you just need to access that property, and as is Base64 encoded, you need to decode it. Try this

"body": {
          "fileContent": "@base64ToString(triggerBody()['$content'])",
          "fileName": "@triggerOutputs()['headers']['x-ms-file-name']"
},

HTH