Error when trying to upload Raster Image with Python

03-08-2021 09:26 AM
New Contributor II

Hello Community,

i've got a Problem with Uploading Rasterimages to the ESRI Portal with Python.

For Feature Layer everything is working well with e.g.

layerproperties['type'] = 'Shapefile'
item = self.gis.content.add(item_properties=layerproperties, data=layerpath)

But if i try to upload a .tif in a .zip and change the 'type' to 'Image Collection' i get a Problem after the Upload when i try to publish:

ValueError: A file_type must be provide, data format not recognized

I tried to publish the Image Collection manually in the portal:

Publish Image Collection error: Exception: null

After that i watched into the Reference and chnanged item.publish() to:


item.publish(publish_parameters=None, address_fields=None, output_type=None, overwrite=False, file_type='Image Collection' , build_initial_cache=False, item_id=None)



File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\arcgis\gis\", line 10353, in publish
elif not buildInitialCache and ret[0]['type'].lower() == 'image service':
KeyError: 'type'

So i added a output_type to the publish function:

item.publish(publish_parameters=None, address_fields=None, output_type='Imagery Layer', overwrite=False, file_type='Image Collection' , build_initial_cache=False, item_id=None)

I got the same error.

So i watched again in the reference:

Publishes a hosted service based on an existing source item (this item). Publishers can create feature, tiled map, vector tile and scene services.
Feature services can be created using input files of type csv, shapefile, serviceDefinition, featureCollection, and fileGeodatabase. CSV files that contain location fields (i.e. address fields or XY fields) are spatially enabled during the process of publishing. Shapefiles and file geodatabases should be packaged as *.zip files.
Tiled map services can be created from service definition (*.sd) files, tile packages, and existing feature services.
Vector tile services can be created from vector tile package (*.vtpk) files.
Scene services can be created from scene layer package (*.spk, *.slpk) files.
Service definitions are authored in ArcGIS Pro or ArcGIS Desktop and contain both the cartographic definition for a map as well as its packaged data together with the definition of the geo-service to be created.

Seems for me, i cant upload and publish any images...
Am i right? Or does anyone know how to solve the problem?


Best regards and thanks a lot for your help

0 Kudos
4 Replies
MVP Esteemed Contributor

Do you have access to ArcGIS Pro? Could you try Build a tile package in ArcGIS Pro and upload to your organization ?

Think Location
0 Kudos
New Contributor II

I do have but i try to automate this step...
I CAN upload tifs to the Portal with clicking in the Portal itself...

But i think i will try to automate the building of such a tile package and then upload it with my Code...


Thanks for your Reply 🙂

0 Kudos
MVP Esteemed Contributor

Yes. I am sure you have already figured it out, but I am still sharing the link to the python script for Create Map Tile Package (Data Management) for anyone looking for it.

Think Location
0 Kudos
New Contributor

Hi Flor,

Maybe you can use following sample below to add an image, logo in AGOL content by setting type = pdf as a tricky.


from arcgis.gis import GIS
import arcgis
import os

gis = GIS("", "myLogin")
manager = arcgis.gis.ContentManager(gis)

#use type=pdf to add your image named miramas.JPG

inRaster = r"C:\Pictures\miramas.JPG"
image_properties = {'type':'PDF', 'description':'image raster','title':os.path.basename(inRaster), 'tags':'jpg', 'access':'Public'}
manager.add(image_properties, data = inRaster)


Hope this help you,



0 Kudos