Show Attachments in Web Map Popup

113592
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

AlexSabrina‌, not sure why the tool is failing to generate a token.  I would recommend trying this from your home computer to see if it is a network issue. 

To your other question, yes you can use this script in task scheduler.  You will need to edit the script and change all the 'arcpy.GetParameterAsText()' to their corresponding values.

Anonymous User

I got to the point where it is working in ArcGIS desktop. No more errors.

I am still having issues with the python script though:

I get this error: "Error generating token AGOL"

Anonymous User

Nevermind I found the issue:

It needed an https not http in the script (I am not sure why). Our AGOL is set as http.

Hi Jake,

Does this script work for a map service as well?  When I try running it on a map service I get the following error:

Craig Prisland‌, no this script will not work with a map service.  The script makes an update to the service, so a Feature Service is required.  However, you could update the feature class the Map Service is based off of.  The attachment URL is created the following way:

http://<service_url>/<objectId>/attachments/<attachmentId>

Ex:

http://ags.esri.com/arcgis/rest/services/PropertyDamage/MapServer/0/2/attachments 

You can dig through the script to find the code that finds which features contain attachments as well as generates the URL.

Thanks for the info Jake.  I tried this again using a feature service hosted on one of our ArcGIS Servers but am still getting the same error as I posted above.  Would you have any ideas why I am getting this?

Thanks again.

craiguwl‌ can you send a screen shot of how you have the tool set up?  Also, what is the size of the field you are trying to update with the path to the attachments?

Jake,

Here's a screenshot of my set up.

I also tried updating the code a little adding in the token URL which I am able to successfully get to but am still getting the error. Thanks,

Craig Prisland‌ how do you have security setup for ArcGIS Server?  Are you using built-in or active directory? A screen shot would help.  Ex:

craiguwl‌ if you are not using Web Tier authentication, you should be able to generate the token successfully.  For you username, try specifying the domain\username, i.e.  gis\jskinner.

Jake,

We are using Active Directory and Web Tier.

Craig Prisland‌ try changing the following line:

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

to:

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

For your username, specify domain\username and see if you can successfully generate the token.

Jake,

This is the error that I receive after using your suggestions.

Jake,

I am able to successfully generate a token when I manually browse to the highlighted path and enter in my credentials in the ArcGIS Server Administrator Directory:

However, when I run the script I get the following error.  When you have any idea on how to resolve this?  Thanks.

craiguwl‌ one thing you can do is replace the line "token = data['token']" with the token you generate manually.  Ex:

token = aslkjp;oaiwue;knv;wkj;kja;lskjdfp;oaiueopwfjw...

I've not seen any reply to this question on this thread but from my experience that seems to be the case. 

craiguwl‌ I believe I figured out what is going on.  You most likely have Anonymous Authentication disabled for the web adaptor.  This will cause an error when trying to access the URL to generate a token.  It works using your web browser because the browser will authenticate your credentials, while the script will not.  To get around this you can enable Anonymous Authentication for the web adaptor, or you can specify the port in the feature service URL.  Ex:

http://ags1.esri.com:6080/arcgis/rest/services/Inspection/FeatureServer/0

If you choose the latter for the workaround, you will need to specify the ArcGIS Server site administrator for the username/password to generate the token.

Hi Jake,

Thanks for the suggestion.  However, I was able to populate the actual feature class that the map service is using by creating a URL using your one of your previous suggestions.  It worked out well.

Thanks again.

Jake Skinner Do you know if there are any plans in the future for ESRI to allow attachments to be displayed as image within the popup. I just find it odd that this functionality wasn't added. 

 

Also, using this script I would have to run the tool after every new addition to the layer in order for the image to appear in the popup correct? 

Benjamin Mittler‌ looking at the Ideas, it appears to be under consideration.  I would recommend promoting this idea:

https://community.esri.com/ideas/9669-show-attachments-in-arcgis-online-pop-up-window?commentID=3684... 

I was having trouble running the script because the token portion was still on the link:

https://services5.arcgis.com/f9aJvXZvmLstTQ3E/arcgis/rest/services/StormwaterFeaturePoints/FeatureSe....

I ended up chopping off everything after the /0 and the script ran fine.  Thanks so much for posting this script!!

Were you ever able to solve the "hasattachment" error? 

I'm currently receiving this error while trying to run the tool. I'm not sure if this would have anything to do with it but i'm trying to use the tool on a feature layer created through Survey123.

I was getting that same error -- make sure you drill down to the last link available.  It should give you the option to "query attachments" at the bottom if you're on the correct page:

Thanks!

Solved one problem only to hit another. Now getting "Error encountered: 'objectIdFieldName'"

bem08c‌ if you share your service to an AGOL group you can invite my username (jskinner_CountySandbox) to it and I can take a look at the service.  Make sure 'SYNC' is enable for the feature service in case I need to download it.

Thanks! Invite sent. 

Hi,

I am having trouble populating the URL field, too.  I have tried lots of iterations using the various pieces of advice you've given throughout this comment string.  However, I continue to strike out.  In the screen grabs below I get token errors - however when I include the token information in my service URL then I get and objectID field error.  Ideas?

I don't know if it matters, but this service is populated via a geoForm and 'seeing' the attachments is for some reason really difficult. 

Thanks for any/all advice.  Christine

Ben, make sure to modify your link by removing the token portion (see my post above).  I ended up just sharing my layer to everyone so I could run the script, and then setting it back to organization after it was finished.

c addison‌ I was not able to reproduce this.  Here is a web map I created with the attachments as pop-ups:

http://arcg.is/110qX0 

I first downloaded the service you shared to the group, and then re-uploaded to AGOL as new feature layer (FloodPlanning).  Here is how I had the tool setup:

Hi Jake,

Thanks. I tried this and still get errors.

I wonder if it is our new geoportal log in system. We have an enterprise

account that also requires a secondary password login (tied to our CAC

card). Would you have any suggestions for a work around? Or maybe once

this feature service is made public, would it be easier to run the script

as it possibly won't require all the log in steps?

Any suggestions are much appreciated.

Thanks,

Christine

addison22‌ the secondary password is most likely causing the issue of generating the token.  The easiest step would be to run the script once the service is shared with 'Everyone'.

Jake, I've encountered the same error as Benjamin: Error encountered: 'objectIdFieldName'

Did you figure out a solution to this? 

seanwhitcomb‌ can you share the service with a Group and invite my user account (jskinner_CountySandbox)?  I will need to take a look at the service.

I've shared the service with a group, but your name does not come up when I try to invite you. I see a jskinner Esri email account, but not your CountySandbox account.

Sean Whitcomb‌ I was not able to reproduce this issue.  Here is how I had the tool setup:

Here is a web map with the pop-ups configured with the attachments:

http://arcg.is/15m5yT 

Thanks for the response. I get this error when trying to access the map at the link you provided: "You do not have permissions to access this resource."

I set up the tool like you did, but using the full URL that includes a token.

Maybe there is some setting that is preventing me from accessing the map, adding you to the group, and using the GP tool. I'm a Publisher rather than an Administrator. Could that be making a difference?

seanwhitcomb‌ do not include the token in the URL.  The username/password generates the token and then appends it to the URL.  Try the web map now.

I removed the token and it worked. Thanks so much!

Edit: It was working, but then it stalled out after performing about 80 attachments. The tool appeared to be running, but no more ObjectIDs were being updated. I let it run for about 30 minutes and there was no progress. I couldn't cancel the tool, and I had to shut down ArcGIS to get it to stop. I ran it again, and this time it got hung up after about 90 attachments. Do you have any idea what might be causing it to hang?

Greetings Jake,

I’m having difficulty with the tool on both AGOL and AGS. Please see how the tool is setup below (AGOL):

Tool Setup

Here is the error:

error

I've read the above issues and saw your instructions to provide access to the file so you can have a look at it. I went ahead and created a group and sent you an invitation from Bvitcp. Looking forward to hearing from you soon.

Thanks in advance

troydawson‌ I did not receive an invitation to the Group you created.

seanwhitcomb‌ how many features are there?  Do all of them contain attachments?

Okay, I resent the invite

Troy Dawson‌ the username is case sensitive in certain situations.  Try the username as BVITCP.  The screen shot you sent shows you are using lower case.  The Group you invited me to shows it as all caps.

Thanks for the super fast response! I will give this a go and report back.

There are 1328 features, and they all have attachments except for one. I have run the tool about a dozen times now, and the farthest it has gotten before stalling out is feature 395.

seanwhitcomb‌ can you share this service with the Group?

I just added you to the group with the service in question. Thank you so much for working on this.

there we go! That worked out nicely. You were correct, the username is case sensitive and making it into all caps did the trick. Thanks again!

seanwhitcomb‌ you may want to check your internet connectivity.  It took almost 2 hours, but the tool ran successfully.

Thank you so much! It looks great.

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