Trying to add item (jpg image) with thumbnail using Python REST API.

1891
2
03-14-2017 08:08 AM
KarolHerszfeld1
New Contributor

Hi! I am adding multiple images (jpg format) to ArcGIS Portal using Python REST API.

So far the part of the code that works (except 'overwrite' parameter) looks like that:

addItem_files = {'file':open(addItem_file_path, 'rb')}
response = requests.post(refererUrl+'/rest/content/users/'
  +username+'/'+addItem_portal_folder+'/addItem?'
  +'token='+portalToken
  +'&overwrite=True'
  +'&type='+addItem_type
  +'&title='+addItem_filename
  +'&tags='+addItem_tags
  +'&culture=pl'
  + '&f=json',
  files=addItem_files)‍‍‍‍‍‍‍‍‍‍‍‍

I have hit a wall when trying to add thumbnails in the process.

Thumbnails are stored in the subfolder and their names correspond to the  original file name ('thumb_*' prefix).

The code with thumbnails implemented look like that:

addItem_files = {'file':open(addItem_file_path, 'rb'),
  'thumbnail':open(addItem_thumbnail_path, 'rb')}
response = requests.post(refererUrl+'/rest/content/users/'
  +username+'/'+addItem_portal_folder+'/addItem?'
  +'token='+portalToken
  +'&overwrite=True'
  +'&thumbnail='+thumbnail_name
  +'&type='+addItem_type
  +'&title='+addItem_filename
  +'&tags='+addItem_tags
  +'&culture=pl'
  + '&f=json',
  files=addItem_files)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Unfortunately there's no result, no thumbnail or even original image.

I would appreciate any suggestions how to properly upload file with thumbnails as well with the overwrite parameter.

Both the thumbnail and overwrite parameters work when using ArcGIS Portal Directory:

/sharing/content/users/user/addItem

Also, I am working with both ArcGIS Portal and ArcGIS Server Linux versions 10.4.1.

Any help on this is highly appreciated.

Thanks!

2 Replies
JonathanQuinn
Esri Notable Contributor

Are you mimicking the parameters used when going through the workflow in the browser with the dev tools or Fiddler running?

0 Kudos
KarolHerszfeld1
New Contributor

I am trying to use the Portal REST API and the POST method to add item to the Portal following the API reference I have:

REST API reference

Same thing can be achieved for one file trough the rest directory, but only for one file at the time:
REST_AddItem

I have found module from ESRI on GitHub that have "AddItem" function which is basically what I am trying to write myself. But I need to dig into that..

0 Kudos