Show Attachments in Web Map Popup

128952
416
12-14-2015 08:10 AM

Show Attachments in Web Map Popup

I work with a lot of customers that request the ability to display their feature service attachments in the web map's popup rather than a hyperlink.  The attached script will convert the feature services attachments URL to a field.  You can then display the attachment directly in the popup after some configuration.

 

Here is a screen shot on how attachments display within a web map popup by default:

 

Screen1.PNG

 

Below are the steps to show the attached image directly in the popup:

 

1.  Add a TEXT/STRING field (i.e. "Picture")  to the feature service that can support a large amount of characters (i.e. 1,000).

2.  Execute the attached GP tool.

3.  Configure the pop-up to Show Images.  Ex:

 

Screen2.PNG

 

The image will now display directly in the popup.  Ex:

 

Screen3.PNG

 

Notes:

  • the timeout for an ArcGIS Online feature service is set to the max of 15 days.
  • the timeout for an ArcGIS Server service is set to the default 'Lifespan of long lived token'.  The default is 1 day.  This can be changed by going to Server Manager > Security > Settings.  After the long lived token is updated, you can update the expiration parameter on line 33.
  • Since the token will timeout, you can update the parameters in the script so this can be executed with Windows Task Scheduler.  Here is an example of how to configure the parameters:

 

A video of the workflow can be found below:

https://www.youtube.com/watch?v=WpLJBZ9gnuw

Attachments
Comments
ChadKopplin
Frequent Contributor

Thanks Jake, this will be handy for one of my web maps that show the reports for the impaired waters and water bodies across the state.  This could save us sometime on the back end.

BrianO_keefe
Honored Contributor

How does this handle MULTIPLE attachments?

JakeSkinner
Esri Esteemed Contributor

Currently, this code will only show the first attachment in the case where there are multiple.

TroyDawson
Emerging Contributor

Exactly what I'm in search for; however, I don't use ArcGIS Online so how do I get this to work in Portal for ArcGIS? I have gotten as far as replacing the baseURL to my feature service URL and Adding the "picture" field. Can someone advise on whatelse is required?

Thanks in advance,

Looking forward to hearing from you guys soon.

TroyDawson
Emerging Contributor

Any instructions for this to work in portal for Arcgis?

RandallClark2
Frequent Contributor

Can this be configured to work with services hosted on a ArcGIS server and not on AGOL?

Also does this need to be re-ran for each time or is it a one shot deal?

ie if i go out on multiple days and collect data would this have to be ran each day?

TroyDawson
Emerging Contributor

Randall,

I've been trying to get an answer to this debacle for the past two(2) weeks to no avail... Hopefully someone out there can provide some answers.

RandyBurton
MVP Alum

While I have only worked with AGO, it is my understanding that server would work much the same as AGO.  You would be accessing the feature via the REST API.  In the script that Jake attached, you would need to change username, password, baseURL, tokenURL, and referer in lines 4 through 6.

For example, baseURL would point to your servers REST point.  Instead of pointing to "http :// services.arcgis.com /dlFJXQQUk /arcgis/rest/services/DamagedBuildings/FeatureServer/0" , change the "services.arcgis.com/dlFJXQQUk" to point to your server.

I would suggest looking at the REST API documentation for Server.

RandallClark2
Frequent Contributor

I might have a fix.

I posted this on a different forum ​and got a response but i have not tried it out yet. Im going to give a try today or tomorrow but here is link to the post and the response.

I also might try stackexchange

RandallClark2
Frequent Contributor

Hi Randy,

Thanks for responding and you are correct (i think)

Its really just a a matter of figuring out what the replacement values are which for a some of us that are new to this part of GIS, it can be hard to figure out where to start looking.

Hopefully that Intro to ArcGIS REST API class i am currently taking will help

JakeSkinner
Esri Esteemed Contributor

I haven't had a chance to look at this for ArcGIS Server, yet, but the code may work just by changing how the token is generated.  For example, try the following:

tokenURL = 'http://' + server + '/arcgis/admin/generateToken'

params = {'username': username, 'password': password, 'client': 'requestip', 'f': 'pjson'}

req = urllib2.Request(tokenURL, urllib.urlencode(params))

response = urllib2.urlopen(req)

data = json.load(response)       

token = data['token'] 

You will just need to replace 'server' with the name of the ArcGIS Server instance.

JakeSkinner
Esri Esteemed Contributor

Updated the script to a GP tool that will update an ArcGIS Online feature service, or an ArcGIS Server feature service.

MantasButrimavičius1
Frequent Contributor

Could this tool be used for dynamic layers (e. g. collecting data with Collector for ArcGIS)? Or I have to repeat this tool everytime I update feature layer?

necurri_VC_SSO
Occasional Contributor

Great tool! Runs with no error but did not add URLs to the string field in the feature service, which I supplied to the script. The progress dialog indicates "success: False" for all records, yet most do have attachments and they are visible as links in the map.

Attachments_to_Popup.png

AGOL_Popup_Image.png

JakeSkinner
Esri Esteemed Contributor

Hi Neil,

Is it possible for you to share this feature service to a group and invite my user account (jskinner_CountySandbox)?  I can try and download the service to see why the field is not updating.

NeilCurri1
Emerging Contributor

Thanks. Invite sent.

RupaliKiran
Deactivated User

Thanks for the tool! Tried it with one of the services which have single attachments from agol. Even though the service has attacgments, the scripts gives error:

    if data["hasAttachments"] == 1:

KeyError: 'hasAttachments'

Failed to execute (AttachmentstoPopup).

any ideas?

-Rupali

JakeSkinner
Esri Esteemed Contributor

Neil, I was going to download the service using a tool I created, but in order to do that 'Sync' needs to be enabled.  Can you enable this for the service?

NeilCurri1
Emerging Contributor

Done. Thanks for taking a look.

TroyDawson
Emerging Contributor

Greetings All,

I have attached the original python file provided in the above downloadable zip file and also my edited version of the python file. I have NOT been able to get this GP tool working with ArcGIS Server. Can someone please advise as to what other changes are required to the script in order to get this tool working.

Thank in advance

Original

python1- original.jpg

Edited Version

python1.jpg

by Anonymous User
Not applicable

Did you get this to work on ArcServer? I have followed along but continue to get a line 41 error token not defined.

JakeSkinner
Esri Esteemed Contributor

Hi Hunter,

Is the ArcGIS Server service secure?  Also, what type of authentication are you using for your ArcGIS Server security?

I noticed that if you have web tier authentication and the service is not secured, you will still have to specify a username/password.

Ex of web tier authentication:

Screen1.PNG

JakeSkinner
Esri Esteemed Contributor

Hi Troy,

What error are you receiving when you use this tool with an ArcGIS Server service?

by Anonymous User
Not applicable

Jake, Thanks for the quick reply

I was able to move past the line 41 error by switching the token endpoint from my web adapter URL to the Port number URL.

I am now getting hung up on  line 46

  if data["hasAttachments"] == 1:

KeyError: 'hasAttachments'

Failed to execute (AttachmentstoPopup).

Trying to get a bunch  of pictures generated from a collector app moved to a pop up for AGOL and then formatted in a report for water quality reporting.

JakeSkinner
Esri Esteemed Contributor

Hi Hunter,

What type of security do you have implemented for ArcGIS Server?  Is the service itself secure?

If you'd like, you can share the service URL to a Group on ArcGIS Online, and then invite my username (jskinner_CountySandbox) to that group.  I can then view the service and take a look at what's going on.

by Anonymous User
Not applicable

Jake,

Thanks I just sent you a invite to the service. The service is secure, however I shared it on AGOL to you with credentials attached.

AllisonFisher
New Member

THAT WAS SO EASY! Thank you so much!

CraigPrisland2
Regular Contributor

Jake,

This is a great script and I can see several benefits of using it.  However, when I trying running it against an AGO feature service, I get the following error.  All features have an attachment tied to them.  Any assistance would be greatly appreciated.  Thanks in advance!

Attachment Error.PNG

JakeSkinner
Esri Esteemed Contributor

Craig Prisland

I would have to take a look at the service to see what's going on.  You can share the service to a Group and invite my AGOL user, jskinner_CountySandbox, to this group if you'd like.

CraigPrisland2
Regular Contributor

Invite sent.  Thanks again for taking a look at this.  Just a heads up, you will notice that there are several layers in this feature service.  These are all referencing the same data but need certain fields turned on/off depending on CAT selected.

Thanks.

deleted-user-M0V5-IqusbtS
Deactivated User

Hey Jake - any chance I can send you an invite to take a look at service in AGOL I am having trouble getting this tool to run on?  I'm getting stuck at line 41.

JakeSkinner
Esri Esteemed Contributor

Hi Eric,

Sure, my username is jskinner_CountySandbox.  Also, please make sure 'Sync' is enabled on the service.

deleted-user-M0V5-IqusbtS
Deactivated User

All set Jake; invite sent- sync was already enabled.

Thanks in advance for your time- the feature service I am trying is called 'Geotagged Photos for Midway-Moxee No 1 and Midway-Grandview No 1 2016' :

http://services3.arcgis.com/Iz3chmSt4P7oOoZy/arcgis/rest/services/MIDW_MOXE_MIDW_GRAN_1_AGOL_PublishGeotaggedPhotos/FeatureServer

The field is called ‘GeoTaggedPhoto’.

Eric Sack/GISP

ACS

Geographer III | Civil Design – TELF

Bonneville Power Administration

bpa.gov<http://www.bpa.gov/> | P 360-619-6359 | C 503-957-6734

JakeSkinner
Esri Esteemed Contributor

One other question, what is the referer to your ArcGIS Online Organization?

deleted-user-M0V5-IqusbtS
Deactivated User

I wasn’t sure what that was – is it our Organizational URL?

http://bpagis.maps.arcgis.com/home/index.html

Eric-

JakeSkinner
Esri Esteemed Contributor

Eric,

It doesn't look like the GeoTaggedPhoto field length is large enough.  I downloaded the service using the following tool, changed the field length to 700, and then re-uploaded to ArcGIS Online.  I was then able to successfully run the Attachments to Popup tool.

deleted-user-M0V5-IqusbtS
Deactivated User

Ah – thanks Jake; I created a new one called PhotoView with 700 field length but still get this error and how I have the tool populated.

Eric-

Attachmentsetup.pngattachmenterror.png

JakeSkinner
Esri Esteemed Contributor

Hi Eric,

I see a few errors in how the tool is set up:

1.  You will want to check 'Hosted Feature Service' since you are updating a hosted feature service

2.  The Feature Service URL should reference the index (i.e add /0 at the end of the URL) of the layer you are updating.  Ex:

http://services3.arcgis.com/Iz3chmSt4P7oOoZy/arcgis/rest/services/MIDW_MOXE_MIDW_GRAN_1_AGOL_Publish...

Notice the '/0' at the end of the URL.

3.  The referrer should just be the following (I need to update the help on this):

http://bpagis.maps.arcgis.com

I went ahead and ran the tool:

Screen1.PNG

I also created a web map:

https://www.arcgis.com/home/webmap/viewer.html?webmap=97ea751bf416486eab413a2d0def8e0d&amp;extent=-1...

If you click on a feature you will see the image directly in the popup.

deleted-user-M0V5-IqusbtS
Deactivated User

Jake - thanks again for your time; it works great!  I was able to configure the pop-up in my web map and am all set.

Best regards-

Eric-

SH013
by
Regular Contributor

Hi there,

I have tried to running the GP script with the following configuration:

- ArcGIS Server Service

- included ArcGIS Server Login and password

- provided a feature Service URL with service index url provided (.../0 etc.)

- Define the field that I want to updated (although i'm not sure how it would know which featureclass to update within my MXD)

I have also ensure that my long-lived tokens is set to more than one day

However this is the result below:

Any help will be greatly appreciated!

JakeSkinner
Esri Esteemed Contributor

bob_says48‌, can you attach a screen shot of how you have the tool setup?

SH013
by
Regular Contributor

This is the error i encountered using the same configuration as seen above.

Thanks in advance,

JakeSkinner
Esri Esteemed Contributor

What is your 'esriFieldTypeOID' set to?  It appears to be error on this.  You can find this out by viewing the service through your REST Services Directory:

SH013
by
Regular Contributor

JakeSkinner
Esri Esteemed Contributor

I would need to take a look at the service to see what's going on.  Anyway to disable the security and send me a private message with REST URL?  Also, you will want to delete the GP error in your previous post.  It contains the REST URL you are using.

SH013
by
Regular Contributor

Hi Jake,

PM Sent, looking forward to hear your thoughts on it 😃

WilliamWang
Regular Contributor

Hi Jake,

New to python...

Should I have changed the script on line 96?

Attached is my setup and updateResults error.

Script Setup

updateResultsError

JakeSkinner
Esri Esteemed Contributor

Hi William,

You will need to change your URL.  You are currently referencing the Map Service.  You will want to reference the Feature Service.  i.e.:

https://URHHere/arcgis/rest/services/Cemetery/HeadstoneGPSfromServer/FeatureServer/0

WilliamWang
Regular Contributor

Jake - Thank you!!! For both the script and quick respond. It worked

My apology for not reading your post carefully.

PhilBeilin1
Regular Contributor

please can any body help me with what I need to do when receiving the error below

thank you in advance and also a big thanks to the creator of the tool.

Version history
Last update:
‎02-28-2022 04:19 AM
Updated by:
Contributors