5

I have an ArcGIS for Desktop Advanced license. I have an attachment enabled feature service in ArcGIS Online. I have thousands of files I wish to attach to it. By current process convention, these files are named according to 2 fields in the attribute table of the feature service (for current and future scripting needs).

What I CAN do:

  • I can attach documents one by one to a local copy of the feature service using attachment manager and successfully sync those attachments.
  • I can create a script that creates a match table for the AddAttachment tool with a field for the Object ID in the feature service and a field storing the file path.
  • I can use this match table to attach all of these files to the local copy of the feature service at once.

What I CANNOT do:

  • Successfully sync this local copy and all of its new attachments to ArcGIS Online.

The Add Attachment tool and its associated arcpy function require the file geodatabase to be outside of an edit session to run. My first guess as to why, after running this tool successfully on a local copy of an AGOL layer, the results can't be sync'ed has to do with it being run outside of an edit session. I'm guessing (but don't actually know) that Desktop -> AGOL sync process sends over the instruction set performed during edit sessions (the attachment manager process for adding attachments requires an edit session). The actions performed outside of an edit session are simply not sent through the sync process, meaning any tools that can't be run in an edit session, like Add Attachments, can't be sync'ed to AGOL.

Is there a known way to attach to an ArcGIS Online feature service in bulk, whether through arcpy, REST service, or some other tool I don't know of?

1 Answer 1

5

You can accomplish this through the REST API. You can add attachments "in bulk" if you set up a Python dictionary where the key is OID and the value is a path to the attachment. Here is how to do it:

  1. clone restapi from GitHub (version 1.0 branch, not 100% complete, but attachments are supported here)
  2. get a dictionary with {OID: PATH, ...} for the attachments and add them using restapi.

See example below:

import restapi

url = 'http://services2.arcgis.com/org_id/arcgis/rest/services/Some_Service/FeatureServer/0'
lyr = restapi.FeatureLayer(url, 'agol_username', 'password')

# form dict, I'm just using one as an example {OID: path}
atts = {24023: r'O:\TEST\Airport_Inventory\IMG_0004.JPG'}

# add all attachments
for oid, att in atts.iteritems():
    lyr.addAttachment(oid, att)
3
  • Thanks for the work on the module. While testing my script, I had a problem with my Python 3.6 installation (the most recent, as of 4/24/2017, 32bit Windows build of Anaconda 4.3.1 from Continuum). On my ESRI ArcGIS provided Python 2.7.13, the "import restapi" (which is all I've used so far) loads up fine. On my Anaconda build, I get a ModuleNotFoundError: No module named 'admin'. I'm currently searching for the source of this module and why it exists on one build but not the other, but I wanted to make you aware of the issue. I'll be testing the token based login and attachments today Commented Apr 27, 2017 at 16:07
  • Thanks for bringing that to my attention. The admin module is a sub module of restapi and I didn't realize I was importing in the __init__.py file. I have removed it in my dev version so when I do the next push it will be fixed. Thanks again!
    – crmackey
    Commented Apr 27, 2017 at 21:50
  • I got it working well. I've been able to create a token, connect at the ArcServer object level and list services, connect to the FeatureService object level and list layers, and connect as a FeatureLayer object. What I can't do is create a cursor from my FeatureLayer object. Is this possible? Error given: ValueError: Not a valid Feature Set from common_types.py line 1077 return Cursor(fs, fields). Is this possible for a FeatureService or only for a MapService? Commented Apr 27, 2017 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.