Select to view content in your preferred language

Thumbnail error when adding item via Python API

2543
4
Jump to solution
06-01-2017 07:37 AM
GarethBaker1
Frequent Contributor

I have a map service (ArcGIS Server 10.2.2) containing a number of layers, each of which I want to add to my Portal (10.5) via the Python API.  The server is not federated with the Portal.

If I manually add the URL for the individual layer then it successfully creates a content item and automatically creates a thumbnail for me showing a snapshot of the data.

However if I use the Python API to add the same URL into a different content item then a thumbnail is not generated. When I go to the content item in Portal it shows an error at the top of the page - see image below:

Error seen when trying to display a thumbnail for an item that has been added via the Python API

This disappears if I click anywhere near it but returns again if I refresh the page.  If I manually edit the thumbnail and upload an image from my PC then I don't see the error again.

So I have two questions:

1. Is it possible for a thumbnail to be automatically generated for me when I create an item via the Python API?

2. If it can't be generated automatically then how can I specify an image file from my PC to be uploaded instead? Or can the image only be referenced by a URL?

For info a sample of my code is below.

layer_properties={
 'title':'Test thumb',
 'description':Test description.',
 'snippet':Test summary.',
 'tags':test',
 'type':'Feature Service',
 'url':'https://myserver/mywebadaptor/rest/services/environmental/designations/MapServer/7'
 }
myLayer = gis.content.add(item_properties=layer_properties)
myLayer

I've looked at the API reference here but there is no example for me to follow
http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.html#contentmanager

Thanks

Gareth

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

You can request the server to create a thumbnail using the export_map method. Once you have a thumbnail, either through export_map or a file on local disk, you can specify that in the 'thumbnail' argument of the 'add' method. Refer to this api reference: arcgis.gis.ContentManager.add

Alternately, you can update an existing item and specify the thumbnail. Refer to this example: managing your content | ArcGIS for Developers 

View solution in original post

4 Replies
by Anonymous User
Not applicable

You can request the server to create a thumbnail using the export_map method. Once you have a thumbnail, either through export_map or a file on local disk, you can specify that in the 'thumbnail' argument of the 'add' method. Refer to this api reference: arcgis.gis.ContentManager.add

Alternately, you can update an existing item and specify the thumbnail. Refer to this example: managing your content | ArcGIS for Developers 

GarethBaker1
Frequent Contributor

Thanks Atma. I think your second link to the API reference is probably the same as I put at the bottom of my original question.  My comment about not having a useful worked example on that page is I think still valid but thankfully the managing your content example has useful guidance on how to specify a path on my local PC for the thumbnail.

0 Kudos
by Anonymous User
Not applicable

Thanks Gareth, we are working toward refining the API ref doc and will take this into consideration. Meanwhile, I could have sent you this guide topic: Accessing and creating content | ArcGIS for Developers which explains how to set a thumbnail at the time of creating a new item. Was this something you were looking for originally?

GarethBaker1
Frequent Contributor

Thanks Atma. I did see that page during my initial research but disregarded it because it didn't specifically mention adding a content item from a loosely coupled ArcGIS Server via URL.  With the benefit of hindsight I can see that the thumbnail example would have been useful despite it relating to a CSV file in that case.  Thanks for all your speedy replies on the matter, very helpful.