Select to view content in your preferred language

Please maintain attachments when using the append method (ArcGIS API for Python) on a hosted feature layer.

1149
4
01-06-2023 12:01 PM
Status: Open
Labels (1)
ZacharyNeumannQK
New Contributor II

Please maintain attachments when using the append method on a hosted feature layer.

 

When following these instructions:

https://www.esri.com/arcgis-blog/products/arcgis-online/data-management/keeping-layers-updated-by-ap...

Append does not maintain attachments that are located in the hosted file geodatabase.

4 Comments
David_Brooks

@ZacharyNeumannQK not sure if this is an idea, because you can select "Maintain Attachments" in the environment variables for Append

ZacharyNeumannQK

This is specifically for the ArcGIS API for Python. You cannot set that in an environment variable for the API... Unless you know something I don't know.

See Reference:

https://developers.arcgis.com/python/api-reference/arcgis.features.html#arcgis.features.FeatureLayer...

 

 

BE4
by

Second this idea! Unable to find way to maintain attachments. Looking to script adding attachments after append-but why the workaround for this?

ZacharyNeumannQK

 

 

 

def add_attachments(survey_monuments_fl, attach_table):
    
    df = pd.read_csv(attach_table)
    
    for s in zip(df['Path'], df['GlobalID']):
        if not type(s[0]) == float: # make sure path is not empty
            attach_path = os.path.join(project_folder_path, s[0])
            globalid = s[1]
            feature = survey_monuments_fl.query(where=f"GLOBAL_TEXT = '{globalid}'")
            objectid = feature.value['features'][0]['attributes']['OBJECTID']
            objectid = int(objectid)

            update(f"Adding attachment {attach_path} to {objectid}")
            survey_monuments_fl.attachments.add(objectid, attach_path)

 

 

 

Idk if this is helpful but I used this to add attachments after appending an item to the FL.
 
And yes, I agree. It's a super annoying work around and does not make any sense as why attachments don't maintain or no option in the api.
 
pd is pandas (I am sure you know that though).
 
Attach table has Path like this. I don't have the full path because of some kind of ESRI documentation I forget where
files\win_20211007_09_30_26_pro.jpg

 

and GlobalID

GlobalID
{09804DA6-F682-48CA-8107-4X8102E16A54}

 

I also needed to save GlobalID as a text field in the Feature Layer I am pretty sure because Esri likes to change those.

 

This is how I made the fl object

 

 

itemid = #itemidhere
survey_monuments_item = gis.content.get(f"{itemid}")
survey_monuments_fl = survey_monuments_item.layers[0]