Show Attachments in Web Map Popup

112211
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

Jake Skinner We spoke earlier, the script works great for one of my customers. However, since a few weeks (could be since the ArcGIS Online update) the photo's do not show up anymore after approx. an hour, instead of 15 days. I expect the token expires real quick. Do you have an idea what the problem might be? 

Tessa Smit‌ I was unable to reproduce this.  Do you know if the customer edited the script at all?

I cannot get this to work with my layer, http://univredlands.maps.arcgis.com/home/item.html?id=327bb77b57cf4898b3e44dc0082a58a1  

if you could provide any help that would be great! When I run the tool it says the layer does not have attachments, however it does so I'm not sure where the problem lies. 

here is what the GP tool looks like when I run it

Hayleigh Pervorse‌ I was unable to reproduce this.  I executed the tool with ArcGIS Pro 2.1.2:

Here is an example web map where you can see the images in the pop-up:

http://arcg.is/0TnTnr 

great thank you for your quick response! I was able to get the to work too. However, I just created a new feature service with similar data (added a few fields) and now I cannot get the tool to work. the feature service url is: https://services.arcgis.com/o6oETlrWetREI1A2/arcgis/rest/services/ROVImagesClean/FeatureServer/0 

and this is the error I am getting

Hi Jake,

Thank you for this - it looks just the ticket.

Sorry - I have some questions as I'm not sure how to get started:

1. Will this work for non-public AGOL services?

2. Will the GP tool work in ArcGIS desktop 10.3.1, Basic license?

3. How can I create a 1,000 char text field (in a shape file, I presume)? The maximum seems to be 254.

4. What's the best way to attach photos to my point shape/FGDB to acheive the pop-up photo once shared in AGOL?

Many thanks again

Andy

Hayleigh Pervorse‌ it looks like you don't not have editing enabled on the feature service.  In ArcGIS Online, go to the item details of the layer > Settings > check Enable Editing:

Andy Bills‌,

1. Will this work for non-public AGOL services?

Yes

2. Will the GP tool work in ArcGIS desktop 10.3.1, Basic license?

Yes

3. How can I create a 1,000 char text field (in a shape file, I presume)? The maximum seems to be 254.

Import the shapefile into a File Geodatabase and then you can create a field in the feature class that is larger than 254.

4. What's the best way to attach photos to my point shape/FGDB to acheive the pop-up photo once shared in AGOL?

Since you are working with a Basic license you won't have the ability to create attachments using ArcGIS Desktop.  You will need to publish the feature class as an ArcGIS Online hosted feature service.  You can then enable attachments on the hosted feature service. 

Has anyone else tried to automate this by copying the results as a python snippet?  I'm trying to do so and I keep getting this error.

Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'AttachmentstoPopup'

Zand Bakhtiari‌ you can update the #Parameters section in the python script.  Ex:

#Parameters
hostedFeatureService = 'true'
agsService = ''
federatedServer = ''
portalURL = ''
username = 'agol'
password = 'gis12345'
baseURL = 'https://services.arcgis.com/o6oETlrWetREI1/arcgis/rest/services/Parcels/FeatureServer/0'
fieldName = 'Picture'

Hello, Thank you for this very useful tool. I'm an error in execution. My entity service is set to update mode. Here is the error message.











Thank you for your help. 
Benoit

Maxime Lemonnier‌ if you want to share the service to a Group and then invite my user account (jskinner_CountySandbox) I can take a look and see what's going on.

Do i run the tool in ArcGIS Online ? If yes how do i do that ?

Hashem Abdo‌, no this tool is executed from either ArcMap or ArcGIS Pro.

Ok thanks so i need to export the shapefile from ArcGIS online back to ArcGIS pro and run the tool. From there how should i import the shapefile back into ArcGIS Online ?

On Tuesday, June 12, 2018, 11:03:14 a.m. EDT, Jake Skinner <geonet@esri.com> wrote:

#yiv7958569080 * #yiv7958569080 a #yiv7958569080 body {font-family:Helvetica, Arial, sans-serif;}#yiv7958569080 #yiv7958569080 h1, #yiv7958569080 h2, #yiv7958569080 h3, #yiv7958569080 h4, #yiv7958569080 h5, #yiv7958569080 h6, #yiv7958569080 p, #yiv7958569080 hr {}#yiv7958569080 .yiv7958569080button td {}

|

GeoNet

|

You have been mentioned

by Jake Skinner in Show Attachments in Web Map Popup in GeoNet - View Jake Skinner's reference to you

Hashem Abdo, no this tool is executed from either ArcMap or ArcGIS Pro.

Participate in the conversation by replying to this email

This email was sent by GeoNet because you are a registered user.

You may unsubscribe instantly from GeoNet, or adjust email frequency in your email preferences

No, you will not need to export to a shapefile.  You will need to grab the REST service URL of your ArcGIS Online hosted feature service.  The tool will update the service using this URL.  Make sure your feature service contains a large text field as outlined in the above steps.

Hi Jake,

Thank you for your help. I have now got a GDB with a 1000 char 'picture' field and downloaded and imported your toolbox. Sorry, I'm a newbie to external GP script use.

I have tried importing the .py script into the toolbox - this appears to work, but has no parameters. I'm not sure on what I should do from here...!

Thank you.

Andy Bills‌ what version of ArcGIS Desktop are you using?

Hi Jake,

I'm using ArcGIS desktop 10.3.1 Basic. Though I may have access to 10.6 Standard and ArcGIS Pro from time to time if that makes significant difference?

Thanks!

Hi There,

I've spent a little bit of time trying to get this working and have finally managed to sort that i had an incorrect username and password. To figure this one out I had to manually grab the json response and display it to see what the error was. 

I suggest it might be worth adding a debug line in the token response section for any errors relating to this.

Cheers.

Andy Bills‌, yes try using the ArcGIS Desktop 10.6 version.  This will include the requests module.

Hi James,

Is the user name/password meant to be our own ArcGIS Online credentials?

Thanks

Andy

Jake,

I tried running this tool and I'm getting an error saying that my feature service does not contain attachments, but there are attachments for each feature in the service. Any thoughts on what might be wrong?

Nate Novak can you share the service to an ArcGIS  group and invite my user account (jskinner_CountySandbox)?  I can take a look and see what's going on.

Hi Jake,

I created the "Picture" field and ran the tool with the correct REST URL. It populated the field just fine (https://serverdomainname/arcgis/rest/services/Development/Thumbnail_Attachment/FeatureServer/0/2/att... ) once I logged on to the web map I got an empty thumbnail. Do you know what could of gone wrong?

Louie Padilla‌, it looks like the attachments are PDFs.  I don't believe pop-ups can display PDFs.  Only images (i.e. JPG, PNG).

Gotcha. It looks like it works now. I have a couple of questions.

Is this something that we will need to run every time we add multiple or replace the attached file? Second, will this show multiple files as a thumbnail? We are looking into collecting about 3-4 pictures per point and want to be able to show the thumbnails for each instead of going into the "More Info" link one at a time. Do you have any suggestions on a better process?

  1. Is this something that we will need to run every time we add multiple or replace the attached file?  Yes.  Note: you can have Windows Task Scheduler execute the script at a given interval
  2. Second, will this show multiple files as a thumbnail?  No, this will only show one attachment

Jake,

I've been doing this for a while with the UCR Botanic Gardens images of the plant specimens, I currently support up two 4 images to be associated with each plant record. Amazingly the tokens have not expired for over 7 months and counting, but my other apps the Tokens are expiring and causing me problems.  If you go to ArcGIS Web Application you can see my current  app.

I don't know how these tokens are currently holding up, I thought that was the normal, but it isn't.

In your code above is the Token everlasting? That's what I'm seeking, never expire!

Also, do you know how to center and resize an image that is brought into a pop-up window? I don't see any parameters to do so in AGOL currently, at least not when the CSS is hosted on Amazon Cloud services which is the case at UCR.

Thank you,

Mike Cohen 

Researching Tokens and their live span I came across the following, can AGOL tokens be set to obtain a new access token automatically and continually refresh forever?  Better yet, permanent tokes. My application for the Botanic Gardens seems to be doing this somehow, but I'm not aware of anything I did to set it up that way, I assumed that was how it always worked.

Short-lived access tokens and long-lived refresh tokens

A common method of granting tokens is to use a combination of access tokens and refresh tokens for maximum security and flexibility. The OAuth 2.0 spec recommends this option, and several of the larger implementations have gone with this approach.

Typically services using this method will issue access tokens that last anywhere from several hours to a couple weeks. When the service issues the access token, it also generates a refresh token that never expires and returns that in the response as well. (Note that refresh tokens can’t be issued using the Implicit grant.)

When the access token expires, the application can use the refresh token to obtain a new access token. It can do this behind the scenes, and without the user’s involvement, so that it’s a seamless process to the user.

The main benefit of this approach is that the service can use self-encoded access tokens which can be verified without a database lookup. However, this means there is no way to expire those tokens directly, so instead, the tokens are issued with a short expiration time so that the application is forced to continually refresh them, giving the service a chance to revoke an application’s access if needed.

From the third-party developer’s perspective, it is often frustrating to have to deal with refresh tokens. Developers strongly prefer access tokens that don’t expire, since it’s much less code to deal with. In order to help mitigate these concerns, services will often build the token refreshing logic into their SDK, so that the process is transparent to developers.

Mike Cohen‌, I don't believe it's possible to create a token that never expires within ArcGIS .  15 days is the maximum a token can exist before it expires.  At that point, the script will have to be re-executed to create a new token.  Windows Task Scheduler can be used to execute this script at an interval.

The reason that your web application seems to have a never expiring token is because the service is shared with 'Everyone'.  When a service is shared with 'Everyone' then you do not need a token to access the service or it's attachments.

Jake,

Is that right?!

So public sharing does not expire, thank you for that information.

Really appreciate the support!

Mike Cohen

GIS Consultant

Sent from my iPhone

Hi Jake

This constantly expiring token is a real pain for us and our users. I cannot understand why it even requires a separate token when the image we are referencing is located within the same service and we are connected already with a token.

Cheers

Joy Miles

GIS Analyst

Data and Information

27 St Georges Terrace, Perth | GPO Box C120 WA 6839

T (08) 9461 1463 | E Joy.Miles@cityofperth.wa.gov.au<mailto:Joy.Miles@cityofperth.wa.gov.au>

www.perth.wa.gov.au<http://www.perth.wa.gov.au/>

<https://www.facebook.com/CityofPerthWA> <https://twitter.com/CityofPerth> <https://www.instagram.com/cityofperth/> <https://www.linkedin.com/company/city-of-perth/>

Joy Miles‌ you can set up the script with your parameters and have Windows Task Scheduler execute it on a given interval (i.e. once every 10 days).  You will no longer have to worry about the token expiring.

Jake,

Great tool, suggestion for a enhancement. support multiple attachments to multiple fields that will hold each link.

Many maps/apps use more than one attachment, what a work flow saver your Tool would be if it could address more than one attachment.

Now if you could figure out a way to resize an image and center it within the popup window I'll buy you dinner! 

Jake,

Your Tool is very helpful, I understand Joy’s View. What would be very helpful would be for you to enhance your Tool to support more than 1 image attachment.

For non-public apps we often have 4 or 5 attachments with 4-5 corresponding fields of 1,000 text length to hold the URLs. Sure would be nice to have a tool to address that work flow.

I can live with running the Tool every 2 weeks.

If only I had control on the size and position of the image inside the pop up my dreams would come true.

Thank you,

Mike Cohen

GIS Consultant

909.705.6953

Sent from my iPhone

Thanks Jake I will look into it.

Joy Miles

GIS Analyst

Data and Information

27 St Georges Terrace, Perth | GPO Box C120 WA 6839

T (08) 9461 1463 | E Joy.Miles@cityofperth.wa.gov.au<mailto:Joy.Miles@cityofperth.wa.gov.au>

www.perth.wa.gov.au<http://www.perth.wa.gov.au/>

<https://www.facebook.com/CityofPerthWA> <https://twitter.com/CityofPerth> <https://www.instagram.com/cityofperth/> <https://www.linkedin.com/company/city-of-perth/>

Hi Jake Skinner‌ - I don't suppose you could post an example of how to run the script with Windows Task Scheduler?

Thanks!

Troy

Troy Wirth‌ you will need to update the Parameters in the script (i.e. change the arcpy.GetParameterAsText to values):

Then, refer to the following link on how to set up Windows Task Scheduler:

Scheduling a Python script or model to run at a prescribed time 

Excellent!  Thanks so much @Jake_Skinner !

Troy

I've run the script for my hosted feature, but I get an error saying the feature service doesn't contain attachments.  Here is the error message:

Executing: AttachmentstoPopup true false false # # # https://services2.arcgis.com/r6iFVcMJeA4kB4GC/arcgis/rest/services/Other_Hazards_AGOL/FeatureServer Picture
Start Time: Tue Aug 07 16:23:15 2018
Running script AttachmentstoPopup...
Feature service does not contain attachments
Completed script AttachmentstoPopup...
Failed to execute (AttachmentstoPopup).
Failed at Tue Aug 07 16:23:16 2018 (Elapsed Time: 1.34 seconds)

Thanks for your response.  I now have another error:

Executing: AttachmentstoPopup true false false # # # https://services2.arcgis.com/r6iFVcMJeA4kB4GC/arcgis/rest/services/Other_Hazards_AGOL/FeatureServer/... Picture
Start Time: Wed Aug 08 09:06:56 2018
Running script AttachmentstoPopup...
Failed script AttachmentstoPopup...

Traceback (most recent call last):
File "\\iowa.gov.state.ia.us\data\dnrusers\jwenck\My Documents\ArcGIS\AttachmentsToPopup.py", line 118, in <module>
if str(data['updateResults'][0]['success']) == 'True':
KeyError: 'updateResults'

Failed to execute (AttachmentstoPopup).
Failed at Wed Aug 08 09:07:01 2018 (Elapsed Time: 4.55 seconds)

John Wenck‌, I took a look at the service and it does not appear to have any attachments.

I only had one attachment thus far, so I disabled the attachments yesterday

and just created a photo field with a link. So right now there are no

attachments for the service. I have another feature I will host later that

has quite a few attachments. I'll run the script on it and see what

happens.

Thanks!

John

John Wenck | Water Trails Coordinator

Iowa Department of Natural Resources

P 515-725-8465| F 515-725-8201 | 502 E. 9th St., Des Moines, IA 50319

www.iowadnr.gov

I'm pretty sure this tool is awesome and it does address my problem directly but I'm using AGOL and I don't even know how or where to begin using the GP Tool. I'm sorry, but how to we run this tool in the first place? 

Azalea Kamellia Abdullah‌ you will need to run this tool in either ArcGIS Desktop or ArcGIS Pro.

Sorry for the late reply. Thanks!!!

UPDATE:

I READ MORE PREVIOUS BURIED COMMENTS AND FOUND THAT SOMEONE ELSE HAD THE SAME ERROR MESSAGE.

THE SOLUTION IS TO PUT AN INDEX NUMBER ON THE END OF THE FEATURE SERVICE URL (SEE JOHN WENK'S POSTING FROM AUGUST)

I have tried to run this on a Feature Service on AGOL that has attachments.  The tool opens fine in Pro, but I get an error message saying that the feature service has no attachments as the error.  Any ideas?

Messages
Start Time: Wednesday, October 17, 2018 2:27:10 PM
Running script Attachments to Popup...
Feature service does not contain attachments
Completed script Attachments to Popup...
Failed to execute (AttachmentstoPopup).
Failed at Wednesday, October 17, 2018 2:27:11 PM (Elapsed Time: 0.42 seconds)

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