Select to view content in your preferred language

Show attachment URL in a field

1098
5
07-17-2023 01:36 PM
swhitcombMCC
New Contributor III

Is there a way to create a field that automatically calculates the URL for an attachment associated with a feature in an AGOL Hosted Feature Layer? 

I am using a webhook to send data from a feature layer to a database through Make.com. All the string and number fields post just fine, but I also need a field that lists the attachment URL that can be used to download/upload attachments into my database.

I want to be able to capture an image and attach it to a feature using Field Maps or Survey123, then have the URL for the attachment automatically populated in a field in the feature layer so the webhook can access the file.

Ideally, I want this to be automatic, not a tool I have to periodically run in Pro because the webhook grabs the data and imports it into the database immediately after the feature is created/updated. If the Attachment URL field is empty, the attachment will not be included in the import. If necessary, I can change the webhook settings and have it run on a timed interval if the only option is a tool that runs on a schedule in ArcGIS.

0 Kudos
5 Replies
jcarlson
MVP Esteemed Contributor

The format for an attachment is

your-feature-service-url/FeatureServer/layer-index/objectid/attachments/attachmentid

Here's a real example:

https://maps.co.kendall.il.us/server/rest/services/Hosted/Food_Inspection_Program/FeatureServer/0/14...

Except that service isn't public, so it probably won't work for you... But it's really just to show you the format.

In Make, you should be able to pull the attachment ID directly:

jcarlson_0-1689627612433.png

Together with the objectid of the feature, you can have Make cobble together the full URL of the attachment and then supply that string to an attribute edit using the "Make HTTP Request" command.

- Josh Carlson
Kendall County GIS
0 Kudos
swhitcombMCC
New Contributor III

This seems like the solution I need, but I can't find attachmentInfo in the list on Make. Searching the list for "attachmentid" turns up nothing. Did I miss a step somewhere?

Here are all the items that come up when I try to add an item to the File URL box:

swhitcombMCC_0-1689632931923.png

Also, the URL for my attachments includes a token at the end. Will that be an issue?

0 Kudos
Caitlin_Todd_LCOR
New Contributor III

Hi @swhitcombMCC  Did you ever find a solution to this? I have a need for a similar issue where I need a feature layer's photo attachments brought into an email.

Thanks!

Caitlin T

Lane County GIS

0 Kudos
swhitcombMCC
New Contributor III

A rep from Make.com recommended I use the API Call tool, but that's beyond my abilities at the moment. I could never figure out how to get it done. Have you had any luck?

0 Kudos
jcarlson
MVP Esteemed Contributor

You can use the HTTP module to send a query to some-layer/FeatureServer/0/<objectid>/attachments?f=json

You'll get back something like this:

{
  "attachmentInfos": [
    {
      "data_size": 647917,
      "exifInfo": null,
      "size": 647917,
      "content_type": "application/pdf",
      "keywords": "",
      "name": "K70917004061.pdf",
      "globalid": "{20305B37-625D-4D10-8075-6ED43C46811D}",
      "id": 7097,
      "attachmentid": 7097,
      "att_name": "K70917004061.pdf",
      "contentType": "application/pdf"
    }
  ]
}

 That JSON object contains the attachmentid property, which you can use to construct the URL as shown in my initial response.

- Josh Carlson
Kendall County GIS
0 Kudos