<\/HEAD>
On some occasions, it may be necessary to have attachments such as a multimedia image in the popup of our web map or web app, however, this is impossible since attachments are not displayed in a field as if it were a hyperlink. It is possible to manually write the address in a field since through the rest we could know what it looks like, which is basically like this: https\/\/server address\/rest\/services\/Hosted\/service name\/layer or table number within the service\/objectid\/attachments\/attachment objectid.<\/P>
<\/P>
But this is ideal if our service consisted of few records it would be an easy task, and the reality is that we usually handle hundreds or thousands of data, that is why I present to you below something I found at this link: URL link to Attachment Photo when the FeatureLayer is not Shared with Everyone<\/A> thanks to John Evans<\/A> . <\/P><\/P>
Before continuing, it is necessary for you to know that in the layer or table where the attachments are located there must be a text field to store the Attachment URL, in this case I created a field called imageurl in the tables where I have the attachments. This is declared in the Script as 'imageurl' so if you have another field where you store the url simply change that in the python script.<\/P>
<\/P>
First of all, you must understand how services work in ArcGIS Online and Portal. They are similar but there are a couple of differences, starting because in Portal all fields of Hosted Services are lowercase, which does not happen in ArcGIS Online.<\/P>
<\/P>
Let's start with the rest, I already mentioned how it goes but here is an example. What we are going to do is show the details of the service I marked.<\/P>
<\/P>
<\/P>
<\/P>
When accessing the details it is important that you observe the id that this service has, this is a unique identifier and for the script it is vital.<\/P>
<\/P>
<\/P>
<\/P>
Now another basic concept you need to know is the rest url, if you look closely, further down on the page you will see that we have two sections one for layers and another for tables, in each of them we have actions that allow activating or performing certain tasks, but the one that concerns us says Service URL, you can access either but you must take into account that the URL of each layer or table is different, on the other hand, what interests us for our objective is the layer or table that has attachments, in my case it is the table (how do I know? just observe that in layers it says "Enable attachments", meaning it does not have and in the table it says "Disable attachments" in other words this is the one that has what we need).<\/P>
<\/P>
In this case I will enter only to layers so you can observe something important, therefore when entering Service URL, it takes us here.<\/P>
<\/P>
<\/P>
<\/P>
In this image I marked two things, first where we can go back to the service that contains all layers and tables, and secondly the ID of the layer, now I will click on the service to see its content and be able to see the ID of all layers and tables that make up the service.<\/P>
<\/P>
<\/P>
<\/P>
In this section at the bottom we can see layers and tables:<\/P>
<\/P>
<\/P>
In my case, I have 1 layer and 2 tables, their respective Id would be:<\/P>
<\/P>
- 0 for the layer
- 1 for the first table (this one has attachments)
- 2 for the second table (also has attachments)<\LI>
< P style = " text - align : justify ; " > < / P > < P style = " text - align : justify ; " > If we enter any of the tables that have attachments you will be able to observe this at the end of the page:< / P > < P > < / P > < P > < IMG __jive_id = " 461075 " class = " image-6 jive-image " src = " https : / / us.v-cdn.net / 6038851 / uploads / legacyfs / online / 461075_pastedImage_7.png " / > < / P > < P style = " text - align : justify ; " > You will notice there is a link used to query (Query) now I will enter that link and we can query information.< / P > < P > < / P > < P > < IMG __jive_id = " 461076 " class = " image-7 jive-image " src = " https : / / us.v-cdn.net / 6038851 / uploads / legacyfs / online / 461076_pastedImage_8.png " / > < / P > < P > < / P > < P style = " text - align : justify ; " > Basically I only queried where: 1=1 which is always true and Return IDs Only just to see objectids from the table.< / P > < P style = " text - align : justify ; " > < / P > < P style = " text - align : justify ; " > Finally I just pressed Query Get button< / P > < P > < / P > < P > < IMG __jive_id = " 461077 " class = " jive-image image-8 " src = " https : / / us.v-cdn.net / 6038851 / uploads / legacyfs / online / 461077_pastedImage_9.png " / > < / P > < P > < / P > < P> And.... this is the result< / P > < P> < / P > < P> < IMG __jive_id = " 461078 " class = " image-9 jive-image " src = " https : // us.v-cdn.net/6038851/uploads/legacyfs/online/461078_pastedImage_10.png" />
import time
from copy import deepcopy
# Connect to FAASYSOPS Portal
oursite = GIS("portal or arcgis online url","user", "password")
#Update the image field
def UpdateImageField() :
# init some stuff
features_to_be_updated = []
field_service_dataframe = ''
try :
# Get Field Service Layer (not the view layer)
field_service = oursite.content.get('service id')
field_service_layer = (field_service.layers)[Layer or table number according to order]
# Build Data Frame
field_service_dataframe = pd.DataFrame.spatial.from_layer(field_service_layer)
# Iterate through dataframe.
for row in field_service_dataframe.iterrows() :
if (row[1]['imageurl'] == None or row[1]['imageurl'] == '') :
# Get ObjectID and set image URL
objID = < span > str(row[1]['objectid'] 14px;">])
img_url = "urloftheview_View/FeatureServer/ID de capa o tabla/{0}/attachment/{0}".format(objID)
# init feature and get feature from service
feature_to_update = ''
feature = field_service_layer.query(where='OBJECTID = ' + objID)
# Make a deep copy so we keep our attributes/structure and update data
feature_to_update = deepcopy(feature.features[0])
# Make Field Update
feature_to_update.attributes['imageurl'] = img_url
features_to_be_updated.append(feature_to_update)
if len(features_to_be_updated) != 0 :
field_service_layer.edit_features(updates = features_to_be_updated)
except :
print ('Error making update. Do some real error catching or something.')
while True :
UpdateImageField()
time.sleep(15)
In this example it is shown with a geographic layer, but if the attachments are in a table (like survey repeats) change this line field_service_layer =(field_service.layers)[Número de la capa o tabla de acuerdo al orden] to this field_service_layer =(field_service.tables)[Número de la capa o tabla de acuerdo al orden]. Note: it is line 31 of the script.
This script once executed does not stop, so it would be good to leave it running on a server, if you want to stop it you must do it manually.
Once you do that you only need to open the service in the web map, and if the attachments are in the layer then you just configure in the pop-up window and in content multimedia add an image.<\/P>
<\/P>
<\/P>
<\/P>
In the next window, add the field that contains the attachment URL, in my case it is imageurl<\/P>
<\/P>
<\/P>
<\/P>
Then click Accept and again Accept. Now, if the attachments are in related tables as in my case, then configure the popup window in the related table or tables in the same way as you do with a layer.<\/P>
<\/P>
Once you finish configuring the pop-up windows, you will be able to see the images in your webapps as follows (in my case I am using web app builder)<\/P>
<\/P>
<\/P>
<\/P>
<\/P>
<\/P>
<\/P>
<\/P>
Note:<\/STRONG> depending on your Internet speed, the image may not appear automatically, so you will need to be a little patient.<\/P><\/P>I hope this is useful to you.....<\/SPAN><\/P><\/BODY><\/HTML>