Hello,
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?
Thanks
joe rodmey
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:
e.g.
https://services.myserver.com/OrgID/ArcGIS/rest/services/light-inventory/FeatureServer/0/queryAttachments
Query Attachments (Feature Service/Layer)—ArcGIS REST API: Services Directory | ArcGIS for Developers
and paste the json in a json viewer like this:
JSON Editor Online - view, edit and format JSON online
You can view the array and get the element count.
OR
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:
Github Source
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:
<SPAN class="keyword token">import</SPAN> logging<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">,</SPAN> re<SPAN class="punctuation token">,</SPAN> datetime <SPAN class="keyword token">from</SPAN> IPython<SPAN class="punctuation token">.</SPAN>display <SPAN class="keyword token">import</SPAN> display <SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS <SPAN class="string token">''' ********************** SCRIPT CONFIGURATION START ********************** '''</SPAN> <SPAN class="comment token">#What is the ID of the Feature Layer you want to download attachments from?</SPAN> FeatureLayerId <SPAN class="operator token">=</SPAN> <SPAN class="string token">'092d075f4b3a40f78cf1329b20b0d5e7'</SPAN> <SPAN class="comment token">#What are your ArcGIS Enterprise/ArcGIS Online credentials? This is case sensitive.</SPAN> PortalUserName <SPAN class="operator token">=</SPAN> <SPAN class="string token">''</SPAN> PortalPassword <SPAN class="operator token">=</SPAN> <SPAN class="string token">''</SPAN> PortalUrl <SPAN class="operator token">=</SPAN> <SPAN class="string token">'https://www.arcgis.com'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Hope that helps.
Derrick
Perfect thanks. I will give it a shot
Hi Joerodney ,
If you look at this blog post you will see that it is much easier to use Arcade for this purpose:
Visualize your attachments in ArcGIS Online with Arcade
(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)
Xander Bakker
Cheers, I wasn't aware of this Type System too.
Any idea why this doesn't work any longer? When I hit run it shows a valid result but will not let me close out the window to save. Also, there is no Attachments function listed under functions.
Happening in both Portal and AGO.
I've been getting the same thing! Any answer/resolution to this?
Download your feature layer to a file geodatabase, then open the attachments table to see the total number of attachments.
Thanks Jeff. Can be effective but not the most elegant or useful. Ideally for me I'd be able to do this within a dashboard where I could list only the features with 2+ attachments and from there launch something to edit/manage the attachments. But the Count(Attachments()) function is not working for me
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.