I have commonly encountered questions regarding the downloading of attachments (e.g. pictures and documents) from ArcGIS Online Feature Layers. The aim of this is to provide an alternative solution to what's currently on offer.
Firstly, the only way attachments are included when exporting data via ArcGIS Online is when exporting as a File Geodatabase. The reason for this is the File Geodatabase is the only format that supports related records. Therefore, the most common answer to accessing Feature Layer attachments outside of ArcGIS Online is to export the Feature Layer as a File Geodatabase, and extrude the data using a script like this through ArcGIS Desktop. There is also a sync script available which can sync a local File Geodatabase with a hosted Feature Layer. These work well, but they do rely on ArcGIS Desktop, and in the case of option one, also require you to download the File Geodatabase (which can grow in size as you add data to it) in advance of running the script.
For this reason, I created a script using the new ArcGIS API for Python which works independently from ArcGIS Desktop. In fact it works directly with a Web GIS, so you don't even have to download a File Geodatabase in order to access your attachments. It can be re-run on a regular basis, and only downloads new attachments to disk if they have not been previously downloaded.
So what does this script do?
- Creates a folder in which feature attachments are stored (e.g. Attachment Downloads)
- Within this folder creates a sub-folder for each layer in the specified Feature Layer
- If the AttachmentStorage variable is set to 'GroupedFolder', attachments are stored in the format ObjectId-AttachmentId-OriginalFileName in one single folder
- If the AttachmentStorage variable is set to 'IndividualFolder', a new folder is created for every feature with an attachment (named using the features Object ID), while the attachments are stored within in the format AttachmentId-OriginalFileName
- If the attachment already exists on disk it will not be downloaded again
- Summary of downloads (total number of downloads and total attachments size) provided as final console output
How do you get setup?
- Follow the ArcGIS API for Python Install and set up guide
- If using Anaconda, you can use the .yml file to create appropriate environment
- If using Startup.bat file, edit (in a text editor) to reference appropriate folders
- Once you get a Jupyter Notebook open, paste the attached .zip file below in an accessible location (and unzip it)
- Open the DownloadAttachments.ipynb file via Jupyter Notebooks and run (click into code and press Crtl+Enter)
- The script will run on a the specified public Feature Layer and download the attachments to the specified Downloads folder
- An associated log file is created in the Logging folder every time you run the script
Notes:
- Update the FeatureLayerId variable to run on your own Feature Layer
- Specify your PortalUserName, PortalPassword if the Feature Layer is secured
- The names of folders are filtered to show only 0-9 and a-Z characters
- This script has not been tested against ArcGIS Enterprise (only Feature Layers hosted in ArcGIS Online), but it should still work
- Code also available through the Esri developer-support GitHub repository