Show Attachments in Web Map Popup

110193
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

Michael Hart‌ can you send a screen shot of how you have the tool setup? 

Also, could you enable Sync on the service and share it to a Group in AGOL?  You can then invite my user account (jskinner_CountySandbox) to this Group so I can take a look.

Jake,

Thanks for the quick reply. Here is a screen shot of the argument entry form for ArcMap 10.5.1:

I have created a group named “Attachments to Popup” and invited you (jskinner_CountySandbox). I have shared the feature service “Brooyar_TEST” with this group. Sync is enabled and all edit options are enabled.

Here is the error message I got in the tool dialogue details:

“Executing: AttachmentstoPopup2 true false false # michael.harte_qgsp ***** https://services1.arcgis.com/HrMiNYsSqqPpLTDE/arcgis/rest/services/Brooyar_TEST/FeatureServer http://qgsp.maps.arcgis.com Picture

Start Time: Thu Mar 08 16:36:34 2018

Running script AttachmentstoPopup2...

Error: Line 34 -- "response = urllib2.urlopen(req)": <urlopen error 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>

Completed script AttachmentstoPopup2...

Failed to execute (AttachmentstoPopup2).

Failed at Thu Mar 08 16:38:41 2018 (Elapsed Time: 2 minutes 7 seconds)”

Thanks for your help with this.

Cheers,

Mike

Michael Harte

Senior Spatial Information Analyst

Spatial Services | Tech Ops

Queensland Parks and Wildlife Service

Department of Environment and Science

Michael Harte‌ you will need to specify the layer in the service by adding a /0 at the end of the URL.  Ex:

https://services1.arcgis.com/HrMiNYsSqqPpLTDE/arcgis/rest/services/Brooyar_TEST/FeatureServer/0 

Jake,

Thanks for getting back so quickly.

I’ve added”/0” to the end of the URL for the feature service as advised (using ArcMap 10.5.1 - Advanced):

Result I get is (same for three attempts to make certain login details correct):

“Executing: AttachmentstoPopup2 true false false # michael.harte_qgsp ***** https://services1.arcgis.com/HrMiNYsSqqPpLTDE/arcgis/rest/services/Brooyar_TEST/FeatureServer/0 http://qgsp.maps.arcgis.com Picture

Start Time: Fri Mar 09 09:11:26 2018

Running script AttachmentstoPopup2...

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

Completed script AttachmentstoPopup2...

Failed to execute (AttachmentstoPopup2).

Failed at Fri Mar 09 09:11:28 2018 (Elapsed Time: 1.23 seconds)”

Tried same on ArcGIS pro. Same error.

Thanks for your help.

Cheers,

Mike

Michael K. Harte

Senior Spatial Information Analyst

Spatial Services

QPWS

Department of Environment and Science

Michael Harte‌ I believe the issue is your username.  In certain scenarios it is case sensitive.  You are specifying michael.hart_qgsp, but upon viewing your username in AGOL it's Michael.Harte_qgsp.  Here is a screen shot of how I had the tool setup in ArcMap:

This completed successfully:

I created a new feature service (brooyar_withAttachments) and a new web map (http://arcg.is/1f04bm) both shared with the Group you invited me to.  The web map shows an example of the pop-up:

Jake,

Thanks for your help. This worked.

Cheers,

Mike

Michael K. Harte

Senior Spatial Information Analyst

Spatial Services

QPWS

Department of Environment and Science

Hello Jake! Great tool. I can't wait to put it to use but keep getting an error:

Do you have any suggestions on what to do with this error?

Many thanks

Lidia

Lidia Dudina‌ your username will be case sensitive.  Sign into ArcGIS Online and view your username by clicking on it at the top right:

For example, mine is jskinner_CountySandbox.  This tool will error if I specify jskinner_countysandbox.  I will want to make sure I have it exactly as it is here.

Jake,

Did this message come to me in error instead of going to ‘Lidia Dudina”?

Cheers,

Mike

Michael K. Harte

Senior Spatial Information Analyst

Spatial Services

QPWS

Department of Environment and Science

Really nice!  I am going to share this with users.

Thanks Jake. It worked! 

Thanks Jake, this is a great tool. At the company for which I use this tool, it only works outside of their own internal network. When running the tool while connected to their network it returns this error:

In english: No connection could be made because the target machine actively refused it. 

I suspect this is a firewall issue. Do you have any suggestions?

Tessa Smit‌ can the user access the following URL:

https://www.arcgis.com/sharing/rest/generateToken 

The script makes a call to this URL to generate a token.  If the company is unable to, they will need to open up their firewall to allow access to the above.

Jake Skinner‌ 

Thanks for your quick reply. Yes, they can access that URL:

Tessa Smit‌ have the user try the simple script below to see if they can generate a token.  You will need to specify another username/password:

import requests, json

# Disable warnings
requests.packages.urllib3.disable_warnings()

username = "agol"
password = "gis12345"

tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com', 'expiration': str(21600)}

r = requests.post(tokenURL, data = params, verify=False)
response = json.loads(r.content)
token = response['token']
print(token)

jskinner-esristaff‌ Also with this script I keep getting the Win10061 error. I sent you a PM with the full error info.

Jake Skinner‌  I am also having trouble with the token part of the code.  I keep getting this error (the **** in the services url were added on purpose):

Executing: AttachmentstoPopup true false false # sworkmanhs *****

https://services3.arcgis.com/****/arcgis/rest/services/****/FeatureServer/0 Picture
Start Time: Fri Apr 06 10:13:18 2018
Running script AttachmentstoPopup...
Error: Line 33 -- "response = requests.post(tokenURL, data = params, verify = False)": 'NoneType' object has no attribute 'utf_8_decode'
Completed script AttachmentstoPopup...
Failed to execute (AttachmentstoPopup).
Failed at Fri Apr 06 10:13:18 2018 (Elapsed Time: 0.24 seconds)

Here are the parameters I'm using.

The feature layer is publicly shared with sync enabled. There are two attachments in the feature layer and a lot of nulls.  Can you please help as soon as you can?  Thanks.

stevenmw‌ can you invite my user account (jskinner_CountySandbox) to a Group and share this service to that Group?

Hi Jake.  Thanks for the quick reply. I sent you an invitation to join our ESRI Customer Care group.  I shared the feature layer and service to the group.  

Steven Workman‌ I can't say what's going on with your service.  I re-downloaded the service using the following tool.  I then re-uploaded and ran the script and it executed successfully.  Here is a web map you can take a look at:

http://arcg.is/05fGyz 

Thank you Jake.  I re ran the tool this morning and for some reason it is working. Not sure what the problem was last week.  

I cannot get the tool to work for me. I get errors.

Any ideas?

Thanks.

John

jshell‌ what errors are you receiving?  Can you post a screen shot of how you have the tool setup?

Parameters for the tool.

Second attempt at getting the tool to run

Parameters used in second attempt

Showing Feature in AGOL does include jpg attachments

Jake

I am using the Convert Attachments.tbx tool in ArcCatalog 10.5 if that matters.

Thanks.

John

Jake

I was able to get the script to work.

Thank you.

John

Hi!

I'm getting this error running the script:

This is my data:

Any advice would be appreciated!

Thanks,

Julianna

juliannak‌ can you send a screen shot of how you have the tool setup before you execute it?

Sure thing!

juliannak‌ it looks like you are appending the token to your URL.  You will not need to do this.  The script will take care of this for you.  You will just need to enter the following for the Feature Service URL:

https://services1.arcgis.com/B4MnusZHL3vmqU3t/arcgis/rest/services/Bike_Rack_Locations/FeatureServer...

I am having trouble getting the GP tool to work.  I have made the hosted feature layer Public but when I run the tool I get this error.  I have also added the execute screen shot.  Is there something that I am missing?

Zand Bakhtiari‌ what version of ArcGIS Desktop are you running?  Looks like you are missing the requests module.  Here are instructions on how to download and install:

Installing Python request module on Windows | Klaus Nji's Ramblings on Crafting Great Software 

Jake I am using 10.4.1 would upgrading to 10.5 solve this problem?

I believe the requests module is installed with 10.5.1.  If not, you can manually download and install it following the steps in the above link.

I upgraded to 10.5.1 and the script works beautifully.  However I am not getting this generic image when mapping to the "Picture" field.  

When I go into the attribute table and click one of the new links it takes me to this page on the REST Services Directory.

Zand Bakhtiari‌ can you share the service to an ArcGIS Online group and invite my user account (jskinner_CountySandbox)?  I can take a look at the service.

Jake Skinner‌ I set up a group and invited you.  Let me know if it works for you.

Zand Bakhtiari‌ I went ahead and ran the tool:

It updated the Picture field correctly.  Take a look at the web map below:

http://arcg.is/0nn155 

Note, the token expires in 15 days, so this tool will need to be run again at that time.

So what did you do differently?

It looks like you did not specify a username/password, which will be needed if the service is not shared with 'Everyone'.

Jake Skinner‌ do I need to run this tool on my end now because it is still not showing any images when I add the layer to a map.

Jake Skinner‌ never mind I didn't set up the pop up corrector.  Thanks again for all of your help!  Since this token needs to be updated every 15 days could we run the tool via windows task scheduler as opposed to doing it manually?  Or is there another recommended workflow?

When I tired to run the tool on the other layers I revived this error.  I made sure to put in my username\password.

This error is usually an indication that your username/password is incorrect.  Also, your username is case sensitive.

Jake Skinner‌  hmmmm that's weird I don't have any Uppercase letter in my username according to my profile.  Could it have something to so with our Network Security?  I believe we have SAMIL login set up.

It is most likely the SAML security.  The tool has not been verified with SAML.  If you can, create a ArcGIS Online built-in account to use with this tool.

That worked perfectly! Thank you so much!

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