How To: Transfer attachments created in Collector for ArcGIS from a hosted feature service to the original feature class without losing the attachments
When using ArcGIS Online hosted feature services, users may require attachments from data collected with the Collector for ArcGIS app to be transferred or merged back to the original feature class stored in the geodatabase used to create the feature service.
Achieving this is possible if the attachment data is stored locally without preserving the geometry from the feature service. However, attachments are not retained when exporting hosted feature service data to another feature class in ArcMap. This is expected behavior because attachments are stored in a separate table, and appending the relationship class created to connect the original attachment table to the new feature class attachment table creates a new empty output table without the attachments.
The instructions provided describe how to retain attachments in a hosted feature service when transferring to a file geodatabase feature class, using ArcGIS Online and ArcMap.
In ArcGIS Online, export the feature service with the attachment data from Collector for ArcGIS to a new file geodatabase using the Export to FGDB option in the item details page.
In the Export to File Geodatabase window, provide the title, tags, and summary for the file geodatabase. Specify the folder to save the file geodatabase, and click Export.
When the exporting process completes, click Download to download the file geodatabase for local editing. The file geodatabase contains the feature class along with the relationship class used to link the features to the associated attachments using the GlobalID and REL_GLOBALID fields.
In ArcMap, perform a join to append the attribute fields from the downloaded feature class to the original feature class. To do so, right-click the original feature class, and select Joins and Relates > Join. The join is based on the unique ID fields that exist in both tables. When this step completes, the GlobalID field created in ArcGIS Online is added to the original feature class.
Perform a second join to append the attribute fields from the downloaded attachment table to the joined table created in Step 4. This join is based on the GlobalID and REL_GLOBALID fields in the downloaded attachment table. When this step is completed, the attachment IDs and names from the Collector data is added to the original feature class.
After performing the join, it is good practice to export the feature class to a new feature class to make the join permanent. This may prevent any unexpected behavior caused by an active join. Use the newly joined feature class for subsequent steps in this article.
Add a new text field to the joined table created in Step 5, and populate the field with the attachment file paths using the Field Calculator. To do so, select VB Script as the parser, and insert the following code:
"<path to the folder containing the attachments>\ATT" & [ATTACHMENTID] & "_" & [ATT_NAME]
The following is the result of the Field Calculator:
When the file paths of the attachments batch downloaded in Step 5 are populated for each record in the field, use the Enable Attachments tool to enable attachments on the feature class. Alternatively, right-click the feature class in the Catalog window, and select Manage > Create Attachments.
Use the Add Attachments tool to add the attachments to the feature class. When this step completes, a new relationship class is created for the original feature class containing an attachment table with all the attachments.