Export Attachments Toolbox

8428
16
06-25-2021 02:33 AM
UriGilad_EsriAu
Esri Contributor
32 16 8,428

TheExport Attachments Toolboxprovides 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:

Background

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 theAdd 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, orsetting up a limited scriptwhich 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.
  • 备份和共享附件麻烦s 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

TheExport Attachments Toolboxfacilitates the exporting of attachments from Geodatabases or AGOL/Portal hosted feature services.

Tools

The toolbox has three tools:

  1. Export All Attachments from DatabaseExtracts 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 TableBased onthisEsri 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 & AttachmentsThis tool offers several options:
    1. 只有FGDB: Download a hosted feature service from AGOL/Portal to a local folder as a File Geodatabase.
    2. 只有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 afieldwork_prefix to be namedfieldwork_imagedate.jpg.
  3. Group Name(only available for grouped attachments, seeGrouping Attachmentssection 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 named2020101.jpgrelated to a Streetlight asset type will be saved asStreetlight_20200101.jpg.
  4. Group Name + Type Prefix(only available for grouped attachments, seeGrouping Attachmentssection 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 named2020101.jpgrelated 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 isBrisbane_Assetsand the attachment is20200101.jpgthe attachment will be saved asBrisbane_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 theExport Hosted Feature Layer & Attachmentstool 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.

Environments

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

16 Comments