Select to view content in your preferred language

How do I download all ArcGIS Online attachments from a hosted feature layer made from a Survey123 form?

21111
24
07-20-2020 01:13 PM
KaitlynAbrahamson
Regular Contributor

Hello,

I have seen some work on this question on GeoNet before, but I absolutely can't get my attachments from a hosted feature layer downloaded.  I have a Survey123 feature layer with a photo repeat that I have tried exporting to a file geodatabase without success.  All I get is the standard 1KB file that will not unzip.  I tried creating a replica without success as well; I keep getting error messages.  I also tried using a notebook with script I've found on this site, but I am so new to Python, that I have not been able to get it to work.  Please help!

24 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Kaitlyn Abrahamson‌,

You can use the Feature Class to Feature Class tool in ArcGIS Pro to do this.

KaitlynAbrahamson
Regular Contributor

I can retrieve attachments stored online through my Arc Pro?  How so?

0 Kudos
JakeSkinner
Esri Esteemed Contributor
  1. In ArcGIS Pro, connect to your ArcGIS Online organization
  2. Execute the Feature Class to Feature Class tool, specifying the hosted feature service as the input.  You can browse to the hosted feature service.  By default, Maintain Attachments is enabled in the Environments:

KaitlynAbrahamson
Regular Contributor

Where do the attachments save?  I have many photos attached to each entry.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

The attachments will be saved to a table within a geodatabase.  If you need to export the attachments to disk, you can do this using python:

import os, arcpy
tbl = r"C:\Temp\Python\Test.gdb\Graffiti__ATTACH"
fldBLOB = 'DATA'
fldAttName = 'ATT_NAME'
outFolder = r"C:\Temp\Python\Attachments"

with arcpy.da.SearchCursor(tbl,[fldBLOB,fldAttName]) as cursor:
   for row in cursor:
      binaryRep = row[0]
      fileName = row[1]
      # save to disk
      open(outFolder + os.sep + fileName, 'wb').write(binaryRep.tobytes())

print('Finished')
0 Kudos
KaitlynAbrahamson
Regular Contributor

Please forgive my novice, but do you do this in ArcGIS Pro, in the feature class to feature class tool?  As in a new SQL expression?  I really am not sure how to apply this script.

Do I need to replace these?  "fldBLOB,fldAttName" What do they stand for?

0 Kudos
JakeSkinner
Esri Esteemed Contributor

1.  You can execute the Feature Class to Feature Class by specifying the hosted feature service as your input:

2.  This will create a feature class and attachment table in your geodatabase:

3.  Select the __ATTACH table in the Contents pane and under the Map tab in ArcGIS Pro, select the option Copy Path:

4.  Update the tbl in the python script with this path in a text editor (i.e. Notepad, Notepad++).  Also, update the outFolder variable with the path to where you would like to store the attachments:

import os, arcpy
tbl = r"C:\Temp\Default.gdb\PropertyDamage__ATTACH"
fldBLOB = 'DATA'
fldAttName = 'ATT_NAME'
outFolder = r"C:\Temp\Python\Attachments"

with arcpy.da.SearchCursor(tbl,[fldBLOB,fldAttName]) as cursor:
   for row in cursor:
      binaryRep = row[0]
      fileName = row[1]
      # save to disk
      open(outFolder + os.sep + fileName, 'wb').write(binaryRep.tobytes())

print('Finished')‍‍‍‍‍‍‍‍‍‍‍‍‍‍

5.  In ArcGIS Pro, select the Analysis tab and click Python:

0 Kudos
KaitlynAbrahamson
Regular Contributor

Thank you for such a detailed guide.  Do you have to run it?  I'm not sure how.  I thought you just had to hit enter, but nothing shows up in my output folder.  Will this automatically update if I add records?

Once again, thank you for putting up with my naivety with Python.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Somehow my additional steps were cutoff.  After you open the Python window in ArcGIS Pro, you can copy/paste the updated code with your directory paths into the section Enter python code here.  Click Enter a couple times and it should execute the code.

0 Kudos
KaitlynAbrahamson
Regular Contributor

Is it then possible to edit the layer (split it by attributes, edit attribute data) and re-publish to arcgis online with the respective attachments.  For some reason, I cannot get them to show up.

0 Kudos