Select to view content in your preferred language

Export photos from field maps

09-01-2021 12:24 PM
New Contributor

I want to export the photos collected on my form in fieldmaps. I am able to see them when i open the map in ArcGIS, but I cannot find a way to download all at once.

Tags (1)
3 Replies
MVP Regular Contributor

@FatimaGamino ,The workflow below enables you to add a sensible prefix onto the name of the photo, defined by a field of  your choice in your feature class, and downloads the lot into a folder of your choosing. Otherwise, you'll just end up with a load of photos with the same name.

Extract Attachments from a Hosted Feature Service to a folder with prefix name:

Script BELOW works in Pro

  • Save Feature Service as a FGDB and Download to PC
  • Create a join of feature service to the ATTACH table in FGDB

                                   RELGLOBALID in table, to GLOBALID in FClass.

  • Create a string field in ATTACH table called Name
  • Edit ATTACH table
  • Field calculate the Name field to match your required Prefix for each attachment
  • Run the script, using the Name field as your prefix fielD





import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)
outputPrefix = arcpy.GetParameterAsText(2)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID', outputPrefix]) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = "ATT" + str(item[2]) + "_"
        filename = str(item[3]) + "_" + filenum + str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment






..Maps with no limits..
New Contributor

I can get this to work to line 14, but no further...getting this error:

'str' object has no attribute 'tobytes' 


0 Kudos
New Contributor II
0 Kudos