Show Attachments in Web Map Popup

128891
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
JohnWenck
Occasional Contributor

Sorry, I never got it to work for me using the tool feature within Desktop,

but I think it was because I only had one feature that had an attachment.

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

JakeSkinner
Esri Esteemed Contributor

John Wenck‌ the tool should still work even though you only have one feature that has an attachment.  Can you send a screen shot of how you have the tool setup?

RobbynAbbitt
Regular Contributor

Hi John - I did get it to work quite nicely - in both Pro and Desktop.  They key was putting on the additional index number ("/0") at the end of the service URL.  Thanks for the reply - I hope you get it to work if/when you need it.

Robbyn J.F. Abbitt

GIS Coordinator, GISci Certificate Advisor
Department of Geography
Shideler Hall Room 109
Miami University, Oxford, OH
RobertRayner1
Regular Contributor

Thank you for this tool Jake,

I am having issues running it in Pro on a hosted feature service. It is always having an error looking for token, but I have been instructed we should not need tokens.

I've tried all the settings available and cannot get the script to access the layer and write the attachment location to the Picture field.  Any help would be appreciated.

Thanks,'Rob

JakeSkinner
Esri Esteemed Contributor

Robert Rayner can you provide the URL of the hosted feature service you are using?

RobertRayner1
Regular Contributor

Hi Jake, can I send you in a PM?  Unfortunately our portal requires login and accounts are generated through Active Directory. I have also tried with the token that the REST directory creates when I access this layer appended to the URL above but no luck with that either. Have you confirmed this script will work with hosted layers on Portal?

JakeSkinner
Esri Esteemed Contributor

Robert Rayner‌ yes send me a PM.  Include a screen shot of how you have the tool set up.

Lake_Worth_BeachAdmin
Frequent Contributor

flawless, thanks  

ChristineSeidel
Occasional Contributor

Hi Jake -- Thanks for providing this GP Tool.  I keep getting an error message when I run it.  The message states that the feature service does not contain attachments.  The service is hosted in ArcGIS OnLine and it clearly has attachments.  Any thoughts?

Thanks,

- Chris

JakeSkinner
Esri Esteemed Contributor

Christine Seidel‌ can you share the service to an ArcGIS Online Group and invite my user account (jskinner_CountySandbox)?

ChristineSeidel
Occasional Contributor

Hi Jake – You should be receiving an invite to join the group. Let me know if that doesn’t come thru.

Thanks,

-Chris

JakeSkinner
Esri Esteemed Contributor

Christine Seidel‌ you don't have editing enabled on the feature service.  Once you do, you will set the tool up like below.  Don't forget to specify the layer by append /0 to the end of the URL.

ChristineSeidel
Occasional Contributor

Awesome. Thanks Jake. Once I permitted editing on the feature service, the GP tool worked like a charm and the popup looks great.

Thanks

-Chris

EdDaugherty
New Member

Hello all.  I am running ArcGIS pro 10.5.1

I am looking for help with the following error:

JakeSkinner
Esri Esteemed Contributor

Ed Daugherty‌ can  you share the service to a group in ArcGIS Online and invite my user account (jskinner_CountySandbox)?

EdDaugherty
New Member

Thank you Jake.  I think I shared the correct thing

JakeSkinner
Esri Esteemed Contributor

Ed Daugherty‌ looks like you only shared the service definition to the Group.  You'll need to share the Feature Layer, too.

EdDaugherty
New Member

There you go

JakeSkinner
Esri Esteemed Contributor

Ed Daugherty‌ you will need to add the Picture field before executing the tool.  You can do this in the web map.  Make sure you create it with a large size (i.e. 1,000).

EdDaugherty
New Member

Thank you Jake

JoyMiles
Occasional Contributor

We have found a nice alternative for displaying images in pop-ups in AGOL. We store our image in an Azure CDN store location and load the URL as an attribute. Fast access with no token refresh issues. The downside at the moment is that our images are public and we pay a small storage fee.

CoryBolen1
Occasional Contributor

Hi - Dumb question, but having trouble getting started.  I added 'Picture' field in my AGOL feature service.  Downloaded the toolbox and added new toolbox in ArcMap.  Toolbox is empty, so I thought I would just add the script, but unsure of parameters to define.  What am I missing? 

JakeSkinner
Esri Esteemed Contributor

Cory Bolen‌ what version of ArcGIS Desktop are you using? 

CoryBolen1
Occasional Contributor

Was using 10.3 on Desktop.  I thought about testing it on 10.6, but since the tool was published several years ago, didn't think it would matter.  Your question spurred me to test in 10.6 via Citrix and it worked perfectly and pop-up works as expected in AGOL after configuring!  Thank you!

LidiaDudina
Emerging Contributor

I am getting an error:

Error:  Line 33 -- "response = requests.post(tokenURL, data = params, verify = False)": HTTPSConnectionPool(host='www.arcgis.com', port=443): Max retries exceeded with url: /sharing/rest/generateToken (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',)))

Has anyone had similar one?

ChristineSeidel
Occasional Contributor

Hi Lidia – I’m not certain, but you should check to make sure your feature service in AGOL is editable.

- Chris

JakeSkinner
Esri Esteemed Contributor

Lidia Dudina‌ if you share your service to an ArcGIS Online Group and invite my user account (jskinner_CountySandbox), I can take a look at it for you.

MalcolmWilliamson
Emerging Contributor

Hi Jake,

I just tried the GP tool from both the latest Pro and ArcMap, connecting to a very simple "test" feature service hosted on AGOL. Full edit capabilities, and there are indeed attachments. Yet, when running the tool from either platform, I get a "Feature Service does not contain attachments" error. I've sent you an invitation to join the group that I've shared the feature layer with. Thanks for any insight you can provide!

    -Malcolm Williamson

lxd
by
Regular Contributor

Hi Jake Skinner. I've created group with my feature class and added you as a user. The error that I get is: 

 Max retries exceeded with url: /sharing/rest/generateToken (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',)))

I was thinking maybe I need proxy to be included in the code? It gives the error on line

"response = requests.post(tokenURL, data = params, verify = False)"

Thanks a lot! 

JakeSkinner
Esri Esteemed Contributor

Malcolm Williamson‌ you will need to enable Update capabilities for this service since this tool updates a field.  Also, make sure you specify the /0 in the feature service URL.  After enabling update capabilities, you can set up your tool like below:

JakeSkinner
Esri Esteemed Contributor

Lidia Dudina‌ I believe you are correct that there is a proxy issue.  I was able to execute the tool successfully:

Unfortunately, I don't have a proxy to test against.  I found the following web page that discusses Proxies with the Requests module.  You may just need to add the following:

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}

And then update the response line:

response = requests.post(tokenURL, data = params, verify = False, proxies=proxies)

For now, the Picture field is updated and you should be able to show attachments in the pop-up for the next 15 days.

lxd
by
Regular Contributor

Thank you Jake. It is working now. I have set the proxy as environmental variable and restarted my PC (in case someone else has similar problem). 

MalcolmWilliamson
Emerging Contributor

Thank you, Jake - it was the missing layer number (/0) that was preventing it from working. All is good now!

twirth
by
New Contributor

Hi Jake Skinner‌ - Thanks again for this great script. I've been using it a lot. I would like to run this directly on a hosted feature service that is connected to a survey123 form. Do you think that would work and would it mess anything up? Thanks and sorry if someone has asked this and I did not see it!

Troy

JakeSkinner
Esri Esteemed Contributor

Troy Wirth‌ you can add a text field (i.e. Picture) with a large size (i.e. 1000) to the survey, and then publish the survey.  When running the tool, you can specify this field.  I haven't tested, but should work.

OrcaMaritime
Emerging Contributor

I'm getting this error when I'm running the Tool

JakeSkinner
Esri Esteemed Contributor

Orca Maritime‌ you need to specify the index value of the layer at the end of the URL (i.e. FeatureServer/0).

AurelieShapiro
Frequent Contributor

I guess this is really old, but I just ran the script, it says it's successful, but the field I calculated remains empty...runs successfully but field is null (it

JakeSkinner
Esri Esteemed Contributor

Aurelie Shapiro‌ can you share the service to a Group in ArcGIS Online and invite my user account (jskinner_CountySandbox)?  I can take a look and see what's going on.

AurelieShapiro
Frequent Contributor

Thanks Jake!

I started all over and it worked - I was trying to run it on a feature service view, and not the original service.

The original feature service however is an output from survey123. As we are still collecting data, will the survey still work if I have created new fields online, but aren't in the original survey? Also, I need to re-run the tool for future survey responses?

Best,

-aurélie

JakeSkinner
Esri Esteemed Contributor

Aurelie Shapiro‌ I would create the field in the survey, then re-publish the survey if possible.  Yes, you need to run this each time a survey is submitted.  You can set this script up to run using Windows Task Scheduler, so it can execute at a given interval:

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

AurelieShapiro
Frequent Contributor

Excellent – thank you!

Von: Jake Skinner

Gesendet: Freitag, 22. Februar 2019 20:24

An: Shapiro, Aurelie

Betreff: Re: - Show Attachments in Web Map Popup

GeoNet <https://community.esri.com/?et=watches.email.document_comment>

Show Attachments in Web Map Popup

new comment by Jake Skinner<https://community.esri.com/people/jskinner-esristaff?et=watches.email.document_comment> View all comments on this document<https://community.esri.com/docs/DOC-7445-show-attachments-in-web-map-popup?commentID=70727&et=watches.email.document_comment#comment-70727>

IanHamilton2
Occasional Contributor

Hi Jake, I am trying to get your script to run in a toolbox in ArcGIS Pro with a feature service on ArcGIS Online. I am getting a token error. What would be the correct URL to the token generator and also the correct data parameters  to the response POST. I would ultimately like to get something based on you example to work in a geoprocessing service in WebApp Builder widget.  my service URL is of the form https://services1.arcgis.com/....../arcgis/rest/services/...../0 If I use the code as is I get the following error

SERVER: services1.arcgis.com

tokenURL: http://services1.arcgis.com/arcgis/admin/generateToken

response: <Response [200]>

Error: Line 120 -- "token = response.json()['token']": 'token'

    if federatedServer == 'false':
        if username and password:
            try:
                server = baseURL.split("//")[1].split("/")[0]
                arcpy.AddMessage("SERVER: {0}".format(server))
                tokenURL = 'http://' + server + '/arcgis/admin/generateToken'
                #tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
                arcpy.AddMessage("tokenURL: {0}".format(tokenURL))
                params = {'username': username, 'password': password, 'client': 'requestip', 'f': 'pjson', 'expiration': str(1440)}

                response = requests.post(tokenURL, data = params, verify = False)
                token = response.json()['token']
            except:
                PrintException()
        else:
            token = ''

JakeSkinner
Esri Esteemed Contributor

Ian Hamilton‌ if you are using an ArcGIS Online Hosted Feature service, you will generate the token with the following:

#generate token for AGOL Hosted Feature Service
if hostedFeatureService == 'true':
    if username and password:
        try:
            tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
            params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'https://www.arcgis.com', 'expiration': str(21600)}
            response = requests.post(tokenURL, data = params, verify = False)
            token = response.json()['token']
        except:
            PrintException()
    else:
        token = ''
IanHamilton2
Occasional Contributor

Thanks, works now

KimBuck
Occasional Contributor

Where do you need to have all the images you want in the pop up hosted? I wanted to have a folder in AGOL with all the photos in one place, would this work? I am unsure how I link each photo to the right parcel, do they need to share a field, same concept as a join? 

JakeSkinner
Esri Esteemed Contributor

Kim Buck‌ the easiest way to link a photo with the parcel is using attachments:

For feature classes:

Enabling attachments—ArcGIS Help | ArcGIS for Desktop 

Hosted Feature Services:

Manage hosted feature layers—ArcGIS Online Help | ArcGIS 

After you have images added as attachments you can execute this tool to show them in the pop-up.

KimBuck
Occasional Contributor

Thank you Jake. We don't want public users to be able to edit the feature service that we want photos associated with. I am going to add the attachments in ArcMap and then try using your script. We have multiple pictures for each feature, is it possible to display them all in the pop up for one feature? 

JakeSkinner
Esri Esteemed Contributor

Kim Buck‌ unfortunately, you can only display one photo in the pop-up.  You will still need to create a feature service from this data.  The service needs to be editable in order to run the script.  You can create a hosted feature layer view that is not editable, and use this in your web maps/applications.

KellyGerrow
Esri Alum

Check out this additional way to show attachments in a web map pop-up:

https://community.esri.com/community/gis/web-gis/arcgisonline/blog/2019/03/22/show-attachments-in-po... 

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