Show Attachments in Web Map Popup

112172
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

I managed to this successfully before for a map but I get this error trying to run it now.

Executing: AttachmentstoPopup false true siteadmin ***** http://gis.auglaizecounty.org/arcgis/rest/services/BrdofElections/VotingPrecinctsTestForPictures/Map... # Picture
Start Time: Wed Jul 19 14:08:25 2017
Running script AttachmentstoPopup...
Failed script AttachmentstoPopup...

Traceback (most recent call last):
  File "c:\program files (x86)\arcgis\desktop10.4\ArcToolbox\Toolboxes\Convert Attachments.tbx#AttachmentstoPopup.py", line 96, in <module>
KeyError: 'updateResults'

Failed to execute (AttachmentstoPopup).
Failed at Wed Jul 19 14:08:25 2017 (Elapsed Time: 0.49 seconds)

Hi Jake,

I ran this tool on a number of hosted feature layers and it worked great! However, these feature layers are continually being updated by field crews using Collector and it appears as though the attachment path gets broken as soon as another user adds/edits geometry/attributes in those feature layers with attachments. This seems to break the photo path for all records in the feature layer. In looking at the paths, it seems like the token gets changed for all attachments in the feature layer ("8?token=iSfCjwRyNOfrk-I......" vs "8?token=fsWapS3kGkwPwVz....."). Any way to avoid this?

Thanks!

Now the thumbnails are not showing, and when I click on them to open the image links, I get sent to a page that says Invalid token. Do you know how to fix this?

Here's the map: ArcGIS Web Application

Receiving the same error... any updates on the solution?

seanwhitcomb‌ the token will only last 15 days.  This is the maximum.  After 15 days you will need to re-execute the tool so that a new token is generated and appended to the attachments URL.

peter.dalrymple‌ I could not reproduce this.  I tested with an ArcGIS Online Hosted Feature service.  Has it been 15 days since the tool has been executed?  The maximum time a token can exists is 15 days.  After 15 days the tool needs to be re-executed to update the attachment URL with a new token.

Greetings Jake,

 

A million thanks once again for figuring out the solution earlier with using this tool with arcgis online (Hosted feature service). However, my major issue is occurring in my on-premise ArcGIS Server (AGS) environment. Please see below for how the tool is setup:

 

 

Here is the error:

 

Please advise.

Thanks in advance

troydawson‌ your specifying the Map Service URL.  This script will edit the service, so you will need to specify the Feature Service URL.  Ex:

.....MAPS/topographic_data/FeatureServer/3

Greetings Jake,

Thanks for taking the time to respond. I made the change but to no avail. The tool is saying that the script was completed successfully yet no photos.

See below:

Please advise.

troydawson‌ I would need to take a look at the service.  You can send me a private message on GeoNET with the service URL if you'd like.  I will also need a username/password if it is secure.

Greetings Jake,

trying to send the details you requested. It appears you need to be following me as well in order for the private massage to work via geonet. Please follow so that I can forward the details.

Hi Jake,

I was able to get my attached photos to display in my pop-ups using your script.  All the photos are of trees in the city parks, so the portrait orientation is generally best.  When they appear in the pop-up, they have been rotated to a landscape orientation--the tree photos are all sideways. Any thoughts on how I might fix this?

Btw, your script is fantastic--the staff in the Parks department love the pop-up photos.

Jeff

njbaker‌ when you open the attachment link (attachment1.jpg) does the photo appear as it does in the pop-up?

When clicking the link attachment1.jpg, the photo appears correctly (in portrait) in a new tab.

Thanks a million for you help Jake... after enabling feature access and executing, the tool worked successfully. 

@Jeff_Baker this is strange behavior.  The pop-up should honor how the photo appears in the attachment.  I'll let you know if I find a workaround.

Jeff Baker‌ if you're still experiencing the photo rotation issue you may want to take a look at this script:

/blogs/StephaniesGISCorner/2017/08/17/how-to-rotate-image-feature-attachments-on-a-hosted-feature-se... 

This tool worked well but I had to /0 after the feature service URL in order for it to work. Cheers!

@Sharon_Janzen, yes always check the Tool Help dialog if you run into issues.  It will provide further information for each parameter:

Thanks for the great tool! I will be using it regularly. 

Is there a version for Python 3.5 so I can run it with ArcGIS Pro 2.0?  I tried updating the script using Pro's Analyze Tools for Pro, but I can't get it to work.  

epena6‌ I went ahead and updated the tool.  It should now work in Pro.

Thanks for doing that! It works like a charm.

I downloaded the tool, and tried to get it to run from ArcMap.  The tool extracted as an empty toolbox, three python scripts, and a pyc file.  So I brought the toolbox into ArcToolbox and tried adding the python scripts, naming them as they are named.  Then I tried running them, but I never was presented with any parameters to fill with login infomation, service name, etc.. Perhaps I did something wrong, or perhaps it is because I am still running 10.3.1?  It looks like AttachmentsToPopup.py is meant to run first. 

RYesri‌ it could be the version of ArcGIS Desktop your using.  The recent update I used 10.5.1.  Are you able to upgrade?

Can you also display an attachment using arcade expression? The problem I have is that I don't know the attachment ID, is there a trick for this in arcade expression?

For example: /FeatureServer/0/1/attachments/X? (X=first attachment ID)

Jake, I have looked all over for a solution like this - thank you for providing it. When I run the toolbox through ArcMap, I get an error saying "Feature service does not contain attachments." I have confirmed that attachments are enabled, the service is editable, and that every object has an attachment. Do you have any suggestions?

Hi Jake, first of all, thank you for putting this script up. Sorry if this is a rather basic question. I've tried using your GP tool a couple of times but keep ending up with this error

 

I'm not sure what's going on, would you be able to advise?

annehulsey‌ and @E_T if you can share the service you are having issues with to a group in ArcGIS Online.  You can then invite my user account (jskinner_CountySandbox) to this Group.  I can take a look to see what's going on.

Hi Jake, I've sent an invite to you for the group. Tried executing the tool again, and this time got a different error:

Error: Line 36 -- "token = data['token']": 'token'

annehulsey your field Popup_URL is not big enought:

Try increasing this to a length of 1,000.

yheta42‌ can you enable 'Sync' on the service (Settings tab > Enable Sync).  I would like to download the service and then re-upload to my Organization.

Sorry about that! Sync should be enabled now.

Evangeline Tai‌ I downloaded the service using the following tool.  I then re-uploaded as a new service to my ArcGIS Online org and was able to successfully run the Attachments to Popup tool.  Here is how I had the tool setup:

You can take a look at the web map here.

Thanks for the help -- I don't know what I'm doing wrong, but I'm getting the same problem as before, Error: Line 36 -- "token = data['token']": 'token'. This is when setting up the tool the same way you did. Is there something I need to change with the token?

jskinner-esristaff Thank you for the tip about 1000 characters for the field. Unfortunately, I still get the same result. I have added a .jpg of the error message to the group I shared with you.

annehulsey‌ for the feature service make sure you specify the layer within the service.  For example, at the end of the URL add a '/0'.  Take a look at my screen shot I sent a couple comments up.

yheta42‌ usernames are case sensitive when run through GP tools.  You are specifying 'eva_tan', but looking at the owner of the user group you shared with me, your username is 'Eva_Tan'.  Try this username and see if you get it work.

Hello, here are my screenshots with errors in both ArcMap & ArcGISpro.  I'm thinking it's not picking up my user & password for my arcgis service?  the password is longer than 5 characters but it seems to default to ***** after I leave the entry cell.  Please advise.

ArcMap Error

GISpro Error

rnrwang‌ the password will be retained, but it will only show 4 * symbols so others will not know the length of your password.  Can you private message me with the feature service URL and a username/password I can use?

Another question for you Jake Skinner‌:

Will having GlobalIDs create a problem when using UpdateFeatures via REST? 

I get the error below in the response after it sends the UpdateFeatures request (when looping through the OIDs looking for attachments in AttachmentsToPopup2x.py):

{u'error': {u'message': u'Unable to complete operation.', u'code': 500, u'details': [u'Unable to perform updateFeatures operation.']}}

I was getting an SSL cert error when sending the json, but I disabled it though urllib2 context:

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE‍‍‍‍‍‍
response = urllib2.urlopen(req, context=ctx)‍‍‍‍‍‍‍‍

Note that the other requests (e.g. getting OID fieldname, checking for hasAttachments) work fine with the SSL workaround, so I don't think that's the problem.

Thanks for your help.

@Aaron_Dorsey, no having GlobalIDs should not cause this error.  I cannot say for sure why you are receiving this error.  If you want to share the service to a Group and invite my user account (jskinner_CountySandbox) I can take a look at it.

Hello jskinner-esristaff‌,

I am using your script with ArcGIS Pro and a hosted feature service. Everything works fine for a few hours and then the links are broken. If I run it again it, the problem will be fixed for a few hours again. Not sure what the problem is. Any ideas?

Thanks,

Troy

troy.wirth

  1. Are you experiencing the same behavior when running the tool with ArcGIS Desktop?
  2. Is the service an ArcGIS Online hosted feature service, or an ArcGIS Server feature service?
  3. Can you share the service to a group in ArcGIS Online and invite my AGOL account (jskinner_CountySandbox)?

must be expiring token on ArcGIS server

Raymond Wang, PE, GISP

Director, Geographic Information Systems

Development Programming

GEODESIGN + RESEARCH + ANALYTICS

550 Newport Center Drive | Newport Beach, California | 92660-7011

Phone 949.720.2333 | Cell 949.636.6406

rwang@irvinecompany.com

Hi Jake Skinner‌,

I haven't tried to run it from desktop. I can give that a shot.  It is a hosted feature layer.  I suspect Raymond Wang‌ is correct that it is a token issue, but not sure how to solve it. Looks like I don't have the adequate privileges to invite you to the group but you should get an invite to the "GIS Survey Pledge" group.  Thanks for your help!

Troy

troy.wirth‌ looks like I didn't set the token expiration for 3.x version of this tool.  It is now set to the maximum (15 days).  Redownload the tool and execute it.  The pop-ups should remain for 15 days.

Thanks jskinner-esristaff,

I will re-run it and let you know if there are any problems!

Troy

I am running this processing tool in ArcGIS PRO to get the images to work in my hosted services, but i keep getting this error. 

I am sorry my coding is not the best, but I looked in the Json for tokens and could not find them. 

Start Time: Wednesday, February 21, 2018 12:32:18 PM
Running script AttachmentstoPopup2...
Generating Token
Error: Line 36 -- "token = d['token']": 'token'
Completed script Attachments to Popup...
Failed to execute (AttachmentstoPopup2).

I am using ArcGIS Pro to run the tool, but ArcGIS Advanced 10.3 to publish the services, as i could not get eh tool or scripts to run in 10.3. I am hosting on AGOL, and not using server or portal. 

thanks in advance for any and all help. 

Andrew, you can share the service to an ArcGIS Online group and invite my user account (jskinner_CountySandbox) to it and I can take a look. 

I am trying to populate an empty field in an AGOL feature service with the AGOL addresses of the photos attached to the service.  I want the ability to have the photos appear in a popup.  I have followed the instructions offered above and run the associated tool from ArcMap 10.4, ArcMap 10.5 and ArcGIS Pro 2.1.  The initial error messages I received were like, "Executing:  AttachmentstoPopup2x, Error: line 36 Token..." (even when using ArcGIS Pro when the initial script should have been calling AttachmentstoPopoup3x).  As recommended in one post from "jskinner-esristaff", I expanded the size of the field for the attachment addressess to 1024.  No luck.  Last week error messages changed to "Error:  Line 34 -- "response = urllib2.urlopen(req)": <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>".  Any assistance would be appreciated.

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