I'm looking for a way to count attachments found within my feature service and return this number. These attachments are images that were collected in Collector.
Would Arcade be the best way to go?
There are a couple of ways to achieve this.
If it's an once off calculatation, you can either:
1) Make a ArcGIS REST API call to Query Attachments to get the json response and count the elements:
and paste the json in a json viewer like this:
You can view the array and get the element count.
2) Run a python script to query the feature layer.
The following script downloads the attachments, takes a total file-size count as well as total number of attachments:
You can also trim it down so it only returns the count and not download the attachments.
The variable of interest is "downloadCounter"
Provide the username, password, and feature layer id in the following lines:
import logging, os, re, datetime from IPython.display import display from arcgis.gis import GIS ''' ********************** SCRIPT CONFIGURATION START ********************** ''' #What is the ID of the Feature Layer you want to download attachments from? FeatureLayerId = '092d075f4b3a40f78cf1329b20b0d5e7' #What are your ArcGIS Enterprise/ArcGIS Online credentials? This is case sensitive. PortalUserName = '' PortalPassword = '' PortalUrl = 'https://www.arcgis.com'
Hope that helps.
Hi Joerodney ,
If you look at this blog post you will see that it is much easier to use Arcade for this purpose:
(you will need to create a field in your hosted feature service to store the number of attachments, since the Attachments function is not available in the visualization profile)