Count Attachments in ArcGIS Online

3440
4
08-22-2019 08:15 AM
joerodmey
MVP Alum

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

0 Kudos
4 Replies
DerrickWong
Esri Contributor

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/queryAttach...

Query Attachments (Feature Service/Layer)—ArcGIS REST API: Services Directory | ArcGIS for Developer... 

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:

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.


Derrick

joerodmey
MVP Alum

Perfect thanks. I will give it a shot

0 Kudos
XanderBakker
Esri Esteemed Contributor

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)

DerrickWong
Esri Contributor

Xander Bakker

Cheers, I wasn't aware of this Type System too.