Closed boesiii closed 6 years ago
Absolutely, this is very easy with restapi. While there is nothing such as Feature.hasAttachemnt
, both the MapServiceLayer
and FeatureLayer
have a method to find attachments. See the following sample:
import restapi
import os
# sample esri layer for prominent peaks
url = 'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Prominent_Peaks_attach/FeatureServer/0'
lyr = restapi.FeatureLayer(url)
# check for attachments via OID (you can get a list of all OIDs by calling lyr.getOIDs() )
# OID 760 does NOT have an attachment at the time of me writing this sample
atts = lyr.attachments(760) #second param is gdbVersion if using different versions of database
if atts:
# there are attachments, do something here such as download
for att in atts:
# first parm of download() is out location, second (optional) is output name otherwise defaults to att_name
att.download(os.path.join(os.path.expanduser('~'), 'Desktop'))
else:
print('no attachments found')
You can easily iterate though all features to report if they have attachments or not by calling lyr.getOIDs()
. One thing to note here, checking for attachments can get a little chatty as it has to query the server for every OID checked. I hope this helps!
Can I use restapi to check if a feature has an attachment?