1

I want to display the following image Base64 inside the logic Apps email body.

{
"image": [
 "data:image/jpeg;base64,/9j/4AAQSkZJRgA..."
 "data:image/jpeg;base64,/9j/4AAQSkZJRgA..."
 "data:image/jpeg;base64,/9j/4AAQSkZJRgA..."
 "data:image/jpeg;base64,/9j/4AAQSkZJRgA..."
]
}

enter image description here

Inside the setVariable 2 - I'm adding all the details

For the image I'm using items('For_each'), but i get only image, when i submit the form.

Let me know if any one has idea to display multiple images in the email.

<img src=@{items('For_each')} />

<h1 style="text-alig:center">Demo</h1>

<strong><h3>Location</h3></strong>
<hr/>
<strong>Lat:</strong> @{triggerBody()?['latitude']}
<strong>Lon:</strong> @{triggerBody()?['longitude']}
<br />
<br />

<strong><h3>capture On:</h3></strong>
<hr/>
@{triggerBody()?['catpuredon']}
<br />
<br />

<strong><h3>my Car</h3></strong>
<hr/>
@{triggerBody()?['carphoto']}
<br />
<br />

<strong><h3>Car Photos:</h3></strong>
<hr />
<br />
<img src=@{items('For_each')} />

Added the New image after correction enter image description here

PCA
  • 1,677
  • 6
  • 28
  • 45
  • You haven’t showed us how you’re putting that in the email body. You can’t just say all items, you’ll need to construct the html. – Skin Feb 15 '23 at 11:02
  • Updated with email body. – PCA Feb 15 '23 at 11:16
  • I'd say you need to loop through each image in your FOR loop and append to a string variable, not just set a variable. If you think you're doing that, can you show us the contents of the `Set variable` step? – Skin Feb 15 '23 at 11:29

1 Answers1

1

Adding to what @Skin said, I have embedded each item inside <img> tag and appended it to a string variable which is then added in the mail body. Below is how my flow looks like.

enter image description here

As a sample I have taken same image 4 times and below are the results in my mail.

enter image description here

Below is the complete codeview of my logic app

{
"image": {
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Append_to_string_variable": {
                        "inputs": {
                            "name": "StringVar",
                            "value": "@concat('<img src=',item(),'>')"
                        },
                        "runAfter": {},
                        "type": "AppendToStringVariable"
                    }
                },
                "foreach": "@variables('ArrayVar')",
                "runAfter": {
                    "Initialize_variable_-_Image_String": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable_-_Image_String": {
                "inputs": {
                    "variables": [
                        {
                            "name": "StringVar",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_-_Images_Array": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_-_Images_Array": {
                "inputs": {
                    "variables": [
                        {
                            "name": "ArrayVar",
                            "type": "array",
                            "value": [
                                "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...",
                                "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...",
                                "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...",
                                "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA..."
                            ]
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Body": "<p>@{variables('StringVar')}</p>",
                        "Importance": "Normal",
                        "Subject": "Images",
                        "To": "xxx"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/Mail"
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "office365": {
                    "connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastus/managedApis/office365"
                }
            }
        }
    }
}
}
SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18
  • Thanks for your help, Swetha, It worked. In the "Initialize_variable_-_Images_Array" code block i was struggling to understand, whether you have shown an example of hardcoded images dataUrl, but somehow i tried to add the image Array from "when an HTTP request received" and now I'm getting multiple images in the email body. Once again thanks for quick help. – PCA Feb 17 '23 at 08:11