how to use JavaScript to get an attachment in a point from a feature layer

1898
4
Jump to solution
07-22-2021 02:54 PM
HaowenRui
New Contributor II

I hosted a points feature layer on Esri, and I want to pull information off from the feature layer and put it on my web map using Esri Leaflet and JavaScript. For a point with data like this: Screen Shot 2021-07-22 at 3.42.04 PM.png, I have 5 data rows and another attachment. I am able to pull off all the first 5 rows of data using the below sample pathname:

feature.properties.Name        (gives the "Name" row, returns "Snow Condition")

This makes sense since the pathname matches with the GeoJSON file. I just have problems finding attachments, if anyone can give me a pathname to find where the attachment is saved, that will be appreciated.

Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
CourtneyMenikheim
Occasional Contributor

Have you tried looking at AttachmentInfo or AttachmentContent in the 4.x API?

If you'd rather work with the REST API, try getting the attachmentInfos for the feature service, then use the attachmentId of the applicable record and get the attachment (documentation says the content is streamed to the user).

Courtney Menikheim | Application Developer | @thecmenikheim

View solution in original post

0 Kudos
4 Replies
CourtneyMenikheim
Occasional Contributor

Have you tried looking at AttachmentInfo or AttachmentContent in the 4.x API?

If you'd rather work with the REST API, try getting the attachmentInfos for the feature service, then use the attachmentId of the applicable record and get the attachment (documentation says the content is streamed to the user).

Courtney Menikheim | Application Developer | @thecmenikheim
0 Kudos
HaowenRui
New Contributor II

Thank you, this method has worked.

BjornSvensson
Esri Regular Contributor

The ArcGIS API for JavaScript makes this easier, but if you're using something like Esri Leaflet...

To find the exact URL for the attachments you can use 
queryAttachments -- see https://developers.arcgis.com/rest/services-reference/enterprise/query-attachments-feature-service-l...

For example using something like:
https://services1.arcgis.com/9NvE8jKNWWlDGsUJ/arcgis/rest/services/QuickCap_Data/FeatureServer/0/que... 

Based on that response the URL to the attachment would be at
https://services1.arcgis.com/9NvE8jKNWWlDGsUJ/arcgis/rest/services/QuickCap_Data/FeatureServer/0/7/a...

PedroVenancio
New Contributor II

Hi @HaowenRui 

Can you please share an example on how do you got the attachment URL and used it on Leaflet L.esri.featureLayer bindPopup?

Thank you very much!

Best regards

0 Kudos