HOW TO
Attachments from a feature class can be exported individually or in a batch to a desired local folder with default filenames. In some instances, the exported attachments must be renamed to match the values in a feature class field. This article provides the workflow to export and rename attachments from a feature class in a batch using a Python script in ArcGIS Desktop.
Note: When working in ArcMap, it is advisable to disable background geoprocessing. To do this, navigate to Geoprocessing > Geoprocessing Options, and uncheck the Enable check box under Background Geoprocessing.
import arcpy
from arcpy import da
import os
#Modify the following to the desired location
#input_table must be the output table from Step 3
inTable = r"<input_table>"
fileLocation = r"<desired_folder>"
#Modify field_name1 and field_name2 to the desired field name
with da.SearchCursor(inTable, ['DATA', '<field_name1>', '<field_name2>']) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = "ATT" + str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment
del cursor
The image below shows the Python script with the altered parameters. In this example, field_name1 and field_name2 are changed to TYPE and FileName respectively.


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