Enable Attachments

998
2
Jump to solution
07-06-2018 04:36 PM
PatrickFilyer
Occasional Contributor II

Is there any way to enable attachments on an existing hosted feature service with the API? 

1 Solution

Accepted Solutions
JeffBigos
Esri Contributor

Hi Patrick,

Using the code below I was able to turn on and off attachments to the featurelayer.

The code is straightforward, it searches for and finds the layer you want to change.

  1. Change the username and password
  2. My FeatureService only had 1 featurelayer in it. so on this line of code was used to access the featurelayer, If you had more FeatureLayers to add attachment capability to you could loop on them.
featLyr = featCollection.layers[0]

Code:
from arcgis.gis import GIS

gis = GIS("https://www.arcgis.com", "<USERNAME>", "<PASSWORD")

srcResults = gis.content.search("title:ServiceAreas",item_type = "Feature Layer")
featCollection = srcResults[0]
featLyr = featCollection.layers[0]

#Get the manager associated with the featurelayer to update
mgr = featLyr.manager

#Update the featurelayer definition to allow attachments
mgr.update_definition({"hasAttachments": False})

Let me know if you have any questions.

Thanks, 

Jeff

View solution in original post

2 Replies
JeffBigos
Esri Contributor

Hi Patrick,

Using the code below I was able to turn on and off attachments to the featurelayer.

The code is straightforward, it searches for and finds the layer you want to change.

  1. Change the username and password
  2. My FeatureService only had 1 featurelayer in it. so on this line of code was used to access the featurelayer, If you had more FeatureLayers to add attachment capability to you could loop on them.
featLyr = featCollection.layers[0]

Code:
from arcgis.gis import GIS

gis = GIS("https://www.arcgis.com", "<USERNAME>", "<PASSWORD")

srcResults = gis.content.search("title:ServiceAreas",item_type = "Feature Layer")
featCollection = srcResults[0]
featLyr = featCollection.layers[0]

#Get the manager associated with the featurelayer to update
mgr = featLyr.manager

#Update the featurelayer definition to allow attachments
mgr.update_definition({"hasAttachments": False})

Let me know if you have any questions.

Thanks, 

Jeff

PatrickFilyer
Occasional Contributor II

Thanks Jeff. This works. 

0 Kudos