Azure Logic Apps - Get Blob Content - Setting Content type
Asked Answered
D

5

5

The Azure Logic Apps action "Get Blob Content" doesn't allow us to set the return content-type.

By default, it returns the blob as binary (octet-stream), which is useless in most cases. In general it would be useful to have text (e.g. json, xml, csv, etc.).

I know the action is in beta. Is that on the short term roadmap?

Denominational answered 24/4, 2017 at 21:41 Comment(2)
Have you tried setting the blob to the correct content-type? #10040903Fiberglass
Yes. The blob was /json.Denominational
D
1

After fiddling much with Logic Apps, I finally understood what was going on.

The JSON output from the HTTP request is the JSON representation of an XML payload:

{
  "$content-type": "application/xml",
  "$content": "77u/PD94bWwgdm..."
}

So we can decode it, but it is useless really. That is an XML object for Logic App. We can apply xml functions to it, such as xpath.

Denominational answered 5/5, 2017 at 22:23 Comment(0)
O
8

So I had a blob sitting in az storage with json in it. Fetching blob got me a octet back that was pretty useless, as I was unable to parse it.

BadRequest. The property 'content' must be of type JSON in the 'ParseJson' action inputs, but was of type 'application/octet-stream'.

So I setup an "Initialize variable", content type of string, pointing to GetBlobContent->File Content. The base64 conversion occurs under the hood and I am now able to access my json via the variable.

No code required.

JSON OUTPUT...

enter image description here

FLOW, NO CODE...

enter image description here

Enjoy! Healy in Tampa...

Olecranon answered 30/1, 2020 at 17:22 Comment(0)
D
7

Workaround I found is to use the Logic App expression base64ToString.

For instance, create an action of type "Compose" (Data Operations group) with the following code:

        "ComposeToString": {
            "inputs": "@base64ToString(body('Get_blob_content').$content)",
            "runAfter": {
                "Get_blob_content": [
                    "Succeeded"
                ]
            },
            "type": "Compose"
        }

The output will be the text representation of the blob.

Denominational answered 24/4, 2017 at 21:59 Comment(2)
thanks that was progressing. i was able to parse it but not able to put that parsed in to a slack message.Memory
I am getting the results as 'click to download' link as it is reading the ftp into a binary. Could not find a way to resolve itMemory
D
1

After fiddling much with Logic Apps, I finally understood what was going on.

The JSON output from the HTTP request is the JSON representation of an XML payload:

{
  "$content-type": "application/xml",
  "$content": "77u/PD94bWwgdm..."
}

So we can decode it, but it is useless really. That is an XML object for Logic App. We can apply xml functions to it, such as xpath.

Denominational answered 5/5, 2017 at 22:23 Comment(0)
L
1
  1. You would need to know the content-type.
  2. Use @{body('Get_blob_content')['$content']} to get the content part alone.
Larva answered 27/6, 2019 at 13:34 Comment(0)
I
0

Is enough to "Initialize Variable" and take the output of the Get Blob Content as type "String". This will automatically parse the content:

parsing blob content by initializing a variable of String type

Ira answered 25/1, 2023 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.