So I have a Survey 123 that captures a photo and stores it as an attachment based on the JSON being passed into my WebHook and the Data displayed in the Item Details data Panel.
The portion of the Webhook for the attachment gives the URL and the Name (See Below). So I thought I could take the URL plus the Name and put it into an <img> src="......." </img> to embed the image into an email MIME format message. When I went to test the resulting URL in my browser it failed with a token-required message. If I add a ?token=...... to the URL am I not creating a security issue?
TIA --
sprintf("<img alt=\"Documenting Photo\" height=\"128\" width=\"128\" src=\"%s/%s\" />", $bodyJSON['feature']['attributes']['Photo'][0]['url'], ['feature']['attachments']['Photo'][0]['name']);
[attachments] => Array
(
[Photo] => Array
(
[0] => Array
(
[globalId] => {..........}
[parentGlobalId] => {..........}
[name] => Photo-20240106-160729.jpg
[contentType] => image/jpeg
[keywords] => Photo
[size] => 86358
[id] => 6
[url] => https://services2.arcgis.com/.............../arcgis/rest/services/......../FeatureServer/0/17/attachments/6
)
)
)
Do you have the image part working? If so, this seems like a security question rather than a "how to" question.
I am not a security expert, so I will point you to this article which discusses securing HTTP actions.
Thank you for the link it's an interesting read. But it really has nothing to do with accessing the Photo attachment from a Survey 123 entry.
So are you still looking for how to attach the photo? If so, try this:
Option A: Attach image in body of email
1. Flow Trigger of When a survey response is submitted
2. Initialize variable (Name is up to you. Type is String)
3. HTTP. For the URI, specify the Image URL (as you pointed out in your initial post). This will automatically create an Apply to each because all image questions are technically arrays. (As such, this works best with a single image).
Method: GET
URI: Image URL
Queries: token / Portal Info Token (see below)
5. Compose. Choose Expression and enter (If you renamed your HTTP step, then that will need to be reflected below):
concat('<img src="',dataUri(body('HTTP')),'"alt=""/>')
6. Set variable to the Outputs of the previous Compose
7. Use that Variable in your email body
Option B: Attach one or more images to email
1. Flow Trigger of When a survey response is submitted
2. Initialize variable (Name is up to you. Type is Array)
3. HTTP.Same as previous example
4***. Set variable. Choose your array. Enter this Value.
[
{
"Name": items('Apply_to_each')?['name'],
"ContentBytes": body('HTTP')
}
]
Name is the name of the image. You can use the Name value in S123, or come up with your own custom name.
ContentBytes is the Body of the previous HTTP step.
5. In the Send an email step, click on Show advanced options > click Switch to input entire array > choose your array variable
*** So this part is variable. You can attach a single image this way. If you want to attach multiple images, you can. But, you need use Append to array variable and add that into its own Apply to each, which complicates things. It is doable though.
Interesting. So this Power Automate process would attach the Image to the email?
I am not using this but rather I am developing a PHP script to receive the Webhook, Generate the email with the Image embedded not attached, and then execute some code to populate/update other Feature Layers and a SQL database.
So all the other parts work, It's just this Photo headache. But when I get a chance I will translate this into PHP and try the Attach instead of Embedding the Image.
Yes. I actually provide both versions: Either embed the image into the email or attach the image(s) to the email (as an attachment). I tested both and they both work.
Thank You.
I have been pulled into another "More important" issue. So it may be a week or more before I can get back to this, but I will close the loop with you when I have more information.
Sounds good! Best of luck.