HI,
I was trying to download the attached photos from my Survey123 app. I exported the data as geodatabase which contains the point data and the attachments. I then copied and pasted the script in the Technical Support: How to batch export attachments from a feature class in ArcMap into a script tool. I followed exactly the How To but the photos were not export.
I have attached a copy of my geodatabase and the script that I used.
Any help is very much appreciated. I need the photos for a report.
Thanks.
Solved! Go to Solution.
I used this script:
from arcpy import da import arcpy import os import subprocess arcpy.env.workspace = r"C:\Projects\Test\hazards.gdb" inTable = "service_b_85814f635e42a59fcbf405bd_hazard_photos__ATTACH" fileLocation = r"C:\Projects\Test\Photos" with da.SearchCursor(inTable, ['DATA','ATT_NAME','GLOBALID'],r"") as cursor: for row in cursor: binaryRep = row[0] fileName = str(row[2]) + ".jpg" open(fileLocation + os.sep + fileName, 'wb').write(binaryRep.tobytes()) del row del binaryRep del fileName
Attached is the photos exported. I usually use the GlobalID so that if i need to change photos and re-import them i can just use the GlobalID to reference the attachment record. Hope that helps.
I used this script:
from arcpy import da import arcpy import os import subprocess arcpy.env.workspace = r"C:\Projects\Test\hazards.gdb" inTable = "service_b_85814f635e42a59fcbf405bd_hazard_photos__ATTACH" fileLocation = r"C:\Projects\Test\Photos" with da.SearchCursor(inTable, ['DATA','ATT_NAME','GLOBALID'],r"") as cursor: for row in cursor: binaryRep = row[0] fileName = str(row[2]) + ".jpg" open(fileLocation + os.sep + fileName, 'wb').write(binaryRep.tobytes()) del row del binaryRep del fileName
Attached is the photos exported. I usually use the GlobalID so that if i need to change photos and re-import them i can just use the GlobalID to reference the attachment record. Hope that helps.
Thank very much, Don.
Hi, thank that was very helpfull !
I still have an issue that I can't solve, the picture definition, any idea how to improve image resolution when exporting with this script ?
Thanks !
Hello,
I am not able to download the attachments:
My situation is:
I have a featureClass created with Arcgis Survey123 Connect from a Excel xlsmform.
After opening the FeatureClass from Portal in Arcgis Pro I use this script:
import arcpy
from arcpy import da
import os
inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)
with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) 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
But I have this Error:
Traceback (most recent call last):
File "T:\01_Software\02_ArcGIS\01_Datenbank\WaloBahn\ArcGIS PRO Python Codes\ExportAttachments.py", line 9, in <module>
for item in cursor:
RuntimeError: A Column was giben that does not exist [DATA]
Possible reason 1: When Survey123 Connect creates automatically a Featureclass from an Excel xlsform file does not create the standard 3 Columns with this name because used another method?: 'DATA', 'ATT_NAME', 'ATTACHMENTID'.
Possible reason 2: I am using as Input the Feature-Class created by Survey123 and I should use a Table (If this is the problem, I do not know how to access to this attachment Table).
Possible reason 3: Should I use as input something like the following? The problem is that I do not know how to find this info (my Feature class is stored in Arcgis Online).
arcpy.env.workspace = r"C:\Projects\Test\hazards.gdb"
inTable = "service_b_85814f635e42a59fcbf405bd_hazard_photos__ATTACH"
Can someone help me?
Regards
Angel
I used this script: