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?

21046
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
RachelGugler
New Contributor

I successfully retrieved photos using this script, but they don't appear to be georeferenced. We are trying to decipher if that is because of the security software on the iPad used to collect the data prevented this from being captured, it isn't collected as exif photo data by QuickCapture (the program we used for this collection), or if it gets stripped away during the downloading process. All the other exif data appeared to be intact. Is it possible to get georeferenced photos from AGOL?

KaitlynAbrahamson
Regular Contributor

I'm realizing that when I export my attachments, I only get the first attachment and not the multiple attachments for each feature.  Any ideas why this is happening and how I can export every attachment?  Is it a setting I need to check or something?

0 Kudos
ThijsBriggeman_Tensing
Regular Contributor

For all ending up in this thread due to googling:

You can use the tool 'export attachments' in ArcGIS Pro 3.4 on AGOL services.

0 Kudos
plantbot
New Contributor

Attachments (photos) are not included in the attribute table when my AGOL map is exported as a .pitemx file for use in ArcGIS Pro. The column that contained those photos (or links to them) is removed from the attribute table when it is opened in ArcGIS Pro. I can download the photos one by one in AGOL, but can't bulk download them there or elsewhere. Is there a way to do that?

0 Kudos
ScottDeNeicev1
New Contributor
There are a couple of ways.

1. First, this python script will extract the images to a to a folder of your choice. It is not very fast though.

#### Downloads GeoPlatform attachments from tables or feature classes

#### Created by: Adam Perteca and modified by Hong Sun, 09/21/2022

#### Update variables where comment has: ***

#### ArcGIS Pro

from arcgis.gis import GIS

import os

from arcgis.features import FeatureLayer

#provide AGO info/credentials for login ***

username = "UserAccount"

password = "UserAccount_Password"

gis = GIS(https://epa.maps.arcgis.com,username,password)

#specify the item id for the feature service ***

fs_id = "316ff6d006d04ce39ead7fe0b3a8c9cb"

#specify the layer id for the feature layer with the attachments you want ***

fl_id = 5

#specify the local folder where you want the attachments downloaded ***

local_path = r"C:\R8Projects\DiamondAsphaltTBA\ExportFiles\Survey123Images"

fs = gis.content.get(fs_id)

fl_url = fs['url'] + '/' + str(fl_id)

fl = FeatureLayer(fl_url)

feat_set = fl.query(where='0=0')

oidFieldName = feat_set.object_id_field_name

oids = [f.attributes[oidFieldName] for f in feat_set.features]

for oid in oids:

attachments = fl.attachments.get_list(oid=oid)

if len(attachments) > 0:

for attachment in attachments:

fl.attachments.download(save_path=local_path, oid=oid, attachment_id=attachment['id'])

print(f"{attachment['name']} downloaded") folder directly from GIS platform:



1. If you have a large number of images, this is the faster way.

You can also copy the feature and attachments to a file gdb in ArcGIS Pro using the Copy Features tool, making sure to check the Include Attachments and in Environments, checking the Preserver GlobalIDs.

Then you can use this script to extract the images from there:

import arcpy

from arcpy import da

import os

inTable = r"Path to file geodatabase\YanktonTBAMultisite.gdb\Photo_FC__ATTACH"

fileLocation = r"Path to folder where images are to be extracted"

arcpy.Exists(r"verify file geodatabase existance\YanktonTBAMultisite.gdb")

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID', 'REL_GLOBALID', 'GLOBALID']) as cursor:

for item in cursor:

attachment = item[0]

filenum = str(item[1])

filename = filenum

open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())

del item

del filename

del attachment

0 Kudos