Show Attachments in Web Map Popup

128939
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
PhilBeilin1
Regular Contributor

and this is how I set it up

thanks in advance

TJ

PhilBeilin1
Regular Contributor

Please I need help on what next to do, below is how I set up the tool and the error I received.

thanks  in advance

TJ

JakeSkinner
Esri Esteemed Contributor

Hi pbeilin9‌,

You will want to specify the machine name in the REST URL and not 'localhost'. 

Tajudeen_OlarewajuAbdulazeez
Deactivated User

Hi,

I had my attachments working after running the script. However, after couple of days, I tested the popup attachments and they are not showing(see below screenshot)!

once I click on the thumbnail, it takes me to a new window and asks my credential as the following screenshot shows. was wondering if someone can tell me what is the problem and how resolve it. Thanks in advance.

JakeSkinner
Esri Esteemed Contributor

Hi Tajudeen,

It looks like you are using an ArcGIS Server service.  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 29.

I would check to make sure your token is not expired.  If it is, you will need to re-execute the script and recreate the pop-up in the web map.

Tajudeen_OlarewajuAbdulazeez
Deactivated User

Hi Jake,

Thanks for the response.How can I update the expiration parameter on line 29. as you see on the following screenshot, does not show line 29. would you please guide me where to find and update line 29.

PhilBeilin1
Regular Contributor

JakeSkinner
Esri Esteemed Contributor

Tajudeen,

That was my mistake, I should have updated the document to reflect the correct line as the script has been updated over time.  You will want to update line 33:

params = {'username': username, 'password': password, 'client': 'requestip', 'f': 'pjson', 'expiration': 1440}

You can change the 'expiration' parameter to 525600, which is one year.  Ex:

params = {'username': username, 'password': password, 'client': 'requestip', 'f': 'pjson', 'expiration': 525600}
AdrianWelsh
MVP Honored Contributor

Jake,

Thanks for posting this. I am finally getting around to trying this and I am having issues. In ArcGIS Pro (1.3.1), I get an error about line 22 in the script (I closed Pro already so I don't remember what it said exactly). In ArcMap (10.3.1) I get this error:

Error generating token: 'token'
Completed script AttachmentstoPopup...
Failed to execute (AttachmentstoPopup).
Failed at Wed Sep 14 06:58:18 2016 (Elapsed Time: 1.67 seconds)

I am not sure what I am doing incorrectly. I have a hosted feature service, I put in my username and password (on a 'protected' service that only my org can see), and I created a text field in my service that is 255 characters long to be used for the picture field. Can you advise me on how I can make this work?

Thanks!

Adrian

FahimehHooshmand
Deactivated User

Hi There,

After running the popup attachment script, the attachments are not showing up on my ArcGIS online related layers.

Would you please guide me to fix it.

Thank You,

Fahimeh

Here is the screen shot of the process and the result:

JakeSkinner
Esri Esteemed Contributor

Hi Adrian Welsh,

Can you send a screen shot of how you have the tool set up?  Also, if you want to create a Group in ArcGIS Online and invite me to it, I can take a look at the service.  My AGOL username is jskinner_CountySandbox.  Be sure 'Sync' is enabled for the feature service.

JakeSkinner
Esri Esteemed Contributor

Fahimeh Hooshmand‌,

Try adding 'http://' before your referer.  If this does not work, you can create a Group in ArcGIS Online and invite me to it, I can take a look at the service.  My AGOL username is jskinner_CountySandbox.  Be sure 'Sync' is enabled for the feature service.

AdrianWelsh
MVP Honored Contributor

Hi Jake,

I did not have Sync set up. I enabled that and ran the tool again - got the same error. I also enabled editing, but that did not change the error.

I will make a new group for my feature layer and invite you to it.

Thanks for taking a look at this!

Adrian

AdrianWelsh
MVP Honored Contributor

Jake,

Here it is from ArcMap 10.3.1

And the error:

JakeSkinner
Esri Esteemed Contributor

Adrian Welsh‌, you will need to specify a Referer since you are using a hosted service.  This is the URL to your ArcGIS Online organization, for example:

http://www.MEIamerica.com.maps.arcgis.com

Without this, you will not be able to successfully generate a token.

JakeSkinner
Esri Esteemed Contributor

Also, it does not appear your feature service has attachments.  It only has a path to where the photo is located.  You will need to convert this to an attachment first.  Check out the following tool to do this:

https://www.arcgis.com/home/item.html?id=473c510504f445d5a6d593cf1a7f1133 

AdrianWelsh
MVP Honored Contributor

Jake,

I wondered about the referer. I put in my org's name like you mentioned and got the same error in Pro. In ArcMap, I got a new set of errors:

I am sort of sure my feature service and respective geodatabase has attachments. When I configure the popups in AGOL, I have the option to list attachments as links:

Then the popup shows the link:

Is this not the right method? Do I still need to run that tool that you listed above?

JakeSkinner
Esri Esteemed Contributor

Your field 'Picture' is not big enough. 

Recreate this field with a size of 600.

AdrianWelsh
MVP Honored Contributor

I was wondering what a good size was! That allowed me to run the tool in ArcMap and it worked! (ArcGIS Pro still gave me the same error). Is 600 always going to be long enough?

I will likely have other questions but I may start a separate question on GeoNet (since I'm looking at a more repeatable-type-process, I think).

Thanks for your help!

JoshuaCarver-Brown1
Occasional Contributor

Hi Jake,

My hosted feature service is configured in the pop up to show images. The body of the url (i.e. https://services.arcgis.com/abc123/ArcGIS/rest/services/FeatureABC/FeatureServer/1) is in the image configuration and the remaining portion for each image is stored in a field and brought in as a variable (i.e. {pic1}). The images are attachments to the feature service's related table, as I have 1:M, and so many images per point. This works after I've accessed the service directory (and I'm guessing, created a token?) but others cannot see the images. Do you know of some solution to this problem? Is there any way users could create a token within thewebmap which would allow access to the images?

Thanks,

Josh

JakeSkinner
Esri Esteemed Contributor

JCarverbrown‌, the tool should retrieve the REST URL to the attachment, add this to a field and append the token at the end of the URL so users will have access to it.  If you want to create a group in AGOL, share the service to this group, and invite me to this group I can take a look at it.  Below is my AGOL account:

jskinner_CountySandbox

LouisDECOMBE
Frequent Contributor

Hi, 

i've got the same error on Arcgis pro 1.3.1.

Any ideas?

The sync is activated? the field "photo" has 800 caracters.

JakeSkinner
Esri Esteemed Contributor

lodecombe_DirEtudes‌,

This tool was written with Python 2.7.  ArcGIS Pro uses Python 3.4, so this tool will not work in Pro.  You will need to use it ArcGIS Desktop.

LouisDECOMBE
Frequent Contributor

Hi,

works perfectly with Arcmap. thanks.

However, is it possible to adapt the script because it seems that we have some proxy issues with our company. Work fine with personal internet connexion but not with company connexion.

Thanks

LouisDECOMBE
Frequent Contributor

HI, 

just little question:

when you said: 

"Notes:

  • the timeout for an ArcGIS Online feature service is set to the max of 15 days."

What does it means? It means after 15 days, the picture will no longer be visible in the web map popup?

Thank for the precision.

Louis

LouisDECOMBE
Frequent Contributor

For information, here is the error i get on my company network:

JakeSkinner
Esri Esteemed Contributor

lodecombe_DirEtudes‌,

Yes, after 15 days the picture will no longer be visible in the pop-up.  You will need to re-execute the tool. 

As for a proxy, I believe this is possible.  I would start a web search of how to implement a proxy using python 2.7.

LouisDECOMBE
Frequent Contributor

Ok Thank you.

I wait for your advice about proxy issues

MikeFrates1
Deactivated User

Thanks for generating this script, it will be very helpful with a project I'm kicking off next year.  I ran it successfully a few weeks ago, but now I'm getting the following error:

Running script AttachmentstoPopup...
Failed script AttachmentstoPopup...

Traceback (most recent call last):
File "\\Share\Scripts\Attachments To Popup GP.py", line 84, in <module>
if len(data['attachmentInfos']) > 0:
KeyError: 'attachmentInfos'

Failed to execute (AttachmentstoPopup).
Failed at Mon Nov 21 10:19:00 2016 (Elapsed Time: 35.62 seconds)

Seems to be bombing when it iterates through the OIDs to find objects that have attachments.  I've verified my attachments are set up correctly and there are attachments in the _ATTACH table.

Any ideas?

JakeSkinner
Esri Esteemed Contributor

MFrates-esristaff‌, you can share the service with a Group in AGOL and invite my account (jskinner_CountySandbox).  I can take a look at the service to see what's going on.

MikeFrates1
Deactivated User

Shared.  The item is the feature service "Signs" table (.../3) that photos are attached to by field crews.  I'm attempting to write the URLs to the "COMMENTS_1" field of this table (string, length 600).

JakeSkinner
Esri Esteemed Contributor

MFrates-esristaff‌, I'm assuming the attachments are associated with the /4 layer.  If so, you will need to create the field within this feature class, and execute the tool on this service layer.

MikeFrates1
Deactivated User

Thanks for looking into this.  The attachments are associated with the /3 layer (signs), which is a table in the geodatabase.  The signs are then related to posts (/4), which is a feature class in the geodatabase.

JakeSkinner
Esri Esteemed Contributor

Not sure if this is going to be possible with a table.  How do you currently view the attachments in ArcGIS Desktop when they are associated with the table?  Also, how did you add the attachments to the table?  Did you use the Generate Match Table and Add Attachments tools?

MikeFrates1
Deactivated User

I'm able to view the attachments in ArcMap (see below) and in a popup in ArcGIS Online/Collector for ArcGIS.  I've verified the proper desktop tools were used to generate the attachment relationship in our enterprise geodatabase.  Also, the "hasAttachments" property for the signs feature service endpoint (/3) says "true", indicating the attachments relationship is valid.  I was able to add and remove attachments (via the service and ArcMap) this morning.

JulieK
by
Regular Contributor

Hello,

This tool works great! The only issue is that it is not able to run for all the features. I have a service with 644 features and the tool runs for few features and then gives error saying

URLError: <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>

I rerun it and updates a few features and again gives the same error.

Any thoughts? Am I missing something? Please help!

Thanks,

Julie

JulieK
by
Regular Contributor

I got it work once. I could see the image in the popup but not anymore. I don't know what changed. Is there any setting I need to take care? Please let me know. when I go to the url in the 'Picture field' it says Invalid token.

JakeSkinner
Esri Esteemed Contributor

jmk201‌ if you create a group in ArcGIS Online, you can share the service to this group and invite me (jskinner_CountySandbox).  I can take a look at the service to see what's going on.

JulieK
by
Regular Contributor

Hi Jake,

I have shared the service and I must say the tool works fine. The issue is that the token expires immediately after I run the tool. I did try changing the expiration parameter but not sure if the pictures will keep showing up. After sometime it expires and no pictures show up in the popup.

params = {'f': 'pjson', 'username': username, 'password': password, 'referer': referer, 'expiration': 525600}

I ran it this morning again and I will be monitoring it. I will let you know if it expires again.

Thanks,

Julie Kottamala

GIS Programmer Analyst

Office of Mapping and Geographic Information

Loudoun County, Virginia.

(703) 737-8217

................................

"plastic, paper and glass are in the wrong place if they're in the trash!"

JulieK
by
Regular Contributor

There you go the token is expired. I modified the script and saved it but do I need to build the toolbox again for it to work? Please help

Thanks,

Julie Kottamala

GIS Programmer Analyst

Office of Mapping and Geographic Information

Loudoun County, Virginia.

(703) 737-8217

................................

"plastic, paper and glass are in the wrong place if they're in the trash!"

JakeSkinner
Esri Esteemed Contributor

Julie Kottamala‌ I downloaded the service and re-uploaded to AGOL so I could have write privileges.  I went ahead and ran the tool on the feature service I uploaded and configured a web map with pop-ups.  Let me know if this is working on your end.  The web map can be found here.

by Anonymous User
Not applicable

Hi all,

I really see the use of this tool for my project but cant get it to work.

1. I am using a hosted feature layer in private group

2. I created a field "picture" of 600 length.

Here is my workflow:

i still get an error:

JakeSkinner
Esri Esteemed Contributor

Hi AlexSabrina‌, if you can share the service to an AGOL group and invite my username, jskinner_CountySandbox, to this group I can take a look.  I may need to temporarily download the service, so can you make sure 'Sync' is checked under the item details > Settings tab.

by Anonymous User
Not applicable

Road Closures

<http://eldoradocounty.maps.arcgis.com/home/item.html?id=a6b2e8ef498b454a93ef9b83633b4c60>

is

the layer that holds some attachments.

by Anonymous User
Not applicable

Thanks!

JakeSkinner
Esri Esteemed Contributor

Alex Gole‌ I could not reproduce this.  Here is the web map with the attachment in the pop-up (there was only one-attachment):

http://countysandbox.maps.arcgis.com/home/item.html?id=6b5c201b8a674540880ebba74554b556 

Here is how I had the tool setup:

by Anonymous User
Not applicable

It seems to work on mine now as well. I am not too sure what I did wrong but thank you for testing with me Jake.

DanAllen
Frequent Contributor

Can this be modified in some way to open a multi-page PDF feature attachment to a specific page number, if the page number is stored in the attribute of the point/line/polygon?  https://helpx.adobe.com/acrobat/kb/link-html-pdf-page-acrobat.html

by Anonymous User
Not applicable

Jake,

Strangely it started acting up again. Any idea? Network?

by Anonymous User
Not applicable

Also, is there a way for me  to create a task scheduler out of that script?

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