Export Attachments Toolbox

06-25-2021 02:33 AM
Esri Contributor
13 2 1,205


The Export Attachments Toolbox provides an easy solution for exporting attachments from a feature service on AGOL/Portal or from a local Geodatabase to a local folder. The Toolbox offers various export options such as distributing the exported attachments into multiple folders according to attachment attributes, adding a prefix to attachment name, and downloading the feature service from AGOL/Portal as a File Geodatabase.

If you like this toolbox I'd appreciate if you give a Kudos. Thanks! :thumbs_up:




Attachments, in particular photos, are a common component in spatial data capture and management. As such, Esri’s feature classes (in Desktop environment) and hosted feature services (in AGOL/Portal environment) can be enabled to store attachments relating to individual features. The attachments are saved as Blobs in a related table, pointing to the parent feature class through a Relationship Class.

While it is possible to batch upload attachments to a feature class by using the Add Attachments Tool, the management of existing attachments in a feature class is limited:

  • Individual attachments can only be viewed in dedicated applications, for example Survey123 Online data viewer, or configured pop-ups in web maps, apps, and ArcGIS Pro.
  • Batch downloading of attachments is possible though external software such as FME, or setting up a limited script which has to be applied separately to each attachment table relating to the feature class. Manual downloading of the data is required if the layer is on AGOL.
  • Large or multiple attachments increase the feature class size quickly making it bulky and less responsive.
  • Backup and sharing of attachments are cumbersome as attachments are ‘hidden’ in a feature class, and easy access is only possible through GIS platforms.

Consequently, many users request a dedicated tool that will allow the easy export of attachments from the feature service to a local folder where they can be managed independently.


Export Attachments Toolbox


The Export Attachments Toolbox facilitates the exporting of attachments from Geodatabases or AGOL/Portal hosted feature services.



 The toolbox has three tools:

  1. Export All Attachments from Database Extracts all attachments from a FGDB or EGDB into a local folder. Attachments can be assigned with various file name prefix options such as parent feature class name, related field value, or a text prefix provided by the user.
  2. Export Attachments from Local Table Based on this Esri support page, this tool extracts all attachments from a single attachment table to a local folder. It is similar to the first tool but applies only to one table at a time and does not include advanced options.
  3. Export Hosted Feature Layer & Attachments This tool offers several options:
    1. Only FGDB: Download a hosted feature service from AGOL/Portal to a local folder as a File Geodatabase.
    2. Only Attachments: Extract all attachments from an AGOL/Portal hosted feature service to a local folder without downloading the hosted feature service.
    3. FGDB + Attachments: Download a hosted feature service from AGOL/Portal and extract all its attachments to a local folder.


Grouping Attachments

When downloading attachments from a geodatabase or a hosted feature service, the user can group the attachment in separate folders based on the related feature attributes. For example, in an asset feature class with asset type associated to each attachment, the tool will download all attachments related to asset x in folder x and all attachments related to asset y in folder y, etc.

The specified group name must be entered by the user in the exact way it appears in the feature class. If the group name is not found as a field in the feature class, the attachments will be downloaded to a folder named ‘No Group Assigned’.


Prefix Options

When downloading attachments, the user can specify an attachment prefix that will be added to the attachment’s name. The prefix can be one of the following:

  1. No Prefix – No prefix will be added to attachment name
  2. Type Prefix – A prefix added by the user to the attachment name. For example, images that only have a date in their name can be added a fieldwork_ prefix to be named fieldwork_imagedate.jpg.
  3. Group Name (only available for grouped attachments, see Grouping Attachments section for more info) – The group name will be added as prefix to attachment name. For example, if the attachments are grouped by asset type, an attachment named 2020101.jpg related to a Streetlight asset type will be saved as Streetlight_20200101.jpg.
  4. Group Name + Type Prefix (only available for grouped attachments, see Grouping Attachments section for more info). The group name will be added as prefix to attachment name, and the user’s prefix will follow. For example, an attachment named 2020101.jpg related to a Streetlight asset type with a user prefix of _fieldwork_ will be saved as Streetlight_fieldwork_20200101.jpg.
  5. Related Feature Class Name – The name of the feature class that holds the attachment will be added as a prefix. For example, if the parent layer name is Brisbane_Assets and the attachment is 20200101.jpg the attachment will be saved as Brisbane_Assets_20200101.jpg.


Toolbox and Scripts


Attached in this blog is a version of the toolbox with the scripts embedded ('imported'). To view the script, right click on the script in Pro and click 'Edit'.


Technical Considerations


AGOL/Portal Access

To use the Export Hosted Feature Layer & Attachments tool make sure you have the appropriate permissions to download hosted feature services or attachments from AGOL/Portal. If you cannot see the ‘Export’ button in the service’s overview page in your AGOL you will not be able to download it with the tool.

If your Portal has a proxy you will need to provide the tool with proxy host name and port number.


The toolbox was created in an ArcGIS Pro 2.6.3 / Python 3.6.10 environment. For best results, run the tools in a similar or upgraded environment. Using previous versions, especially Python 2 versions, is likely to cause the toolbox to encounter errors.


Terms of Use


Support and Upgrades

This toolbox is not an official Esri toolbox. It is therefore not supported or updated. 

Published by Uri Gilad, 25 June 2021