HOW TO
Attachments can be added to a layer in ArcGIS Pro, as described in the following documentation, ArcGIS Pro: Add or remove file attachments, before publishing to ArcGIS Online or Portal for ArcGIS. When a layer contains multiple attachments, it can be tedious to manually calculate the total size of attachments. In addition, the total size may vary considering the different sizes when in disk, during publishing, and the conversion from bytes to kilobytes. This article provides the steps to use ArcGIS API for Python to calculate the total size in a stand-alone Python script or ArcGIS Notebooks.
import arcgis from arcgis import GIS import pandas as pd
#For ArcGIS Online
gis = GIS('https://arcgis.com', 'username', 'password')
print("Connected")
#For Portal for ArcGIS
gis = GIS('https://<machine>.<domain>/<web adaptor name>', 'username', 'password', verify_cert=False)
print("Connected")
item = '<item_ID>' layer = gis.content.get(item) ids = layer.layers[0] fs = ids.query(where="1=1") oids = [f.attributes["OBJECTID"] for f in fs.features]
Note: Edit the index value in 'ids = item.layers[0]' based on the layers that hold the attachments. For example, to calculate the total attachment size in the second layer, replace 0 with 1 in the code.
attached = [ids.attachments.get_list(oid=oid) for oid in oids] print(attached)
print("Total size: " + str(ids.attachments.search(as_df=True)['SIZE'].sum()))
#If additional word is unnecessary, the following line can be used:
print(ids.attachments.search(as_df=True)['SIZE'].sum())
The following is a working sample script and the result console. The calculated file size is in bytes.
import arcgis
from arcgis import GIS
import pandas as pd
gis = GIS('https://arcgis.com', 'user1', 'password1!')
print("Connected")
item = '80d00e2301844ou2435p9284fu87bf'
layer = gis.content.get(item)
ids = layer.layers[0]
fs = ids.query(where="1=1")
oids = [f.attributes["OBJECTID"] for f in fs.features]
attached = [ids.attachments.get_list(oid=oid) for oid in oids]
print (attached)
print("Total size: " + str(ids.attachments.search(as_df=True)['SIZE'].sum()))

Article ID: 000031782
Get help from ArcGIS experts
Start chatting now