How do I upload a raster to ArcGIS Enterprise as an image service using arcpy?

09-19-2023 04:53 PM
Occasional Contributor III

I'm trying to automate a workflow that we perform in ArcGIS Pro. The workflow is taking some rasters that are stored in a FGDB and sharing them as an image service via Portal and a federated server.

Here is the documentation on the manual process that works

The manual steps are

  1. In Catalog (not in a map) right click on the raster and choose "share as web layer"
  2. In the sharing panel choose the option "Copy all Data"
  3. Click Publish

This results in an image service in Enterprise.


However, I cannot seem to script this workflow. I tried using


But it seems to create a Server-only version of the .sddraft. I can stage the file using arcpy.StageService but cannot upload the resulting .sd file to Portal. I even tried manually uploading the .sd file to Portal and Portal gave me a warning that it was an ArcGIS Server file.


import arcpy
from arcgis.gis import GIS

gis = GIS(url="", username="userid", password="pass", set_active=True, expiration = 60, verify_cert=False)
service =r'Test_Image'
source = r'C:\Temp\Upload\20230721_AirPollutionPackage.gdb\SD_0721_1030_PM25_IDW'
sddraft = r'C:\Temp\Upload\SD_0721_1030_PM25_IDW.sddraft'
sdfinal = r'C:\Temp\Upload\'

arcpy.CreateImageSDDraft( raster_or_mosaic_layer= source, out_sddraft=sddraft, service_name=service, server_type= 'ARCGIS_SERVER', 
                          copy_data_to_server=  True, folder_name= None, summary= "Test Image Upload", 
                         tags= "las,image service")
    arcpy.StageService_server(in_service_definition_draft= sddraft, out_service_definition= sdfinal, staging_version=5)
    arcpy.UploadServiceDefinition_server(in_sd_file=sdfinal, in_server="My Hosted Services")
    warnings = arcpy.GetMessages(1)
except Exception as ecp:


0 Kudos
3 Replies
Esri Regular Contributor

I believe the problem you're facing is  CreateImageSDDRaft is meant for publishing to ArcGIS Server. There's a required "connection_file_path" parameter I think you're missing which points to the path of an .ags connection file.


To my knowledge, it is possible to publish through Portal using a different workflow that relies on the ArcGIS API for Python: Create Imagery Layers | ArcGIS API for Python. However, I believe in order to make use of this approach you need to have a portal configured for Raster Analysis.

Occasional Contributor III

Thanks for the response @EarlMedina. Unfortunately, we do not have a Raster Analysis deployment. We only have an ArcGIS Server Advanced and a relational datastore.   

So is there no way to replicate the Share Web Image Layer tool in Arcpy? It seems odd since it can be accomplished via Pro.

Since we are federated I don't believe I can create or use a publisher arcgis server connection, .ags file.

0 Kudos
Esri Regular Contributor

I think you can reasonably simulate the same result for your case. Instead of going through Portal you publish directly to Server and copy the data. It seems like you're publishing single raster datasets? That should be fine under your licensing. All you should have to do to is make some minor changes to your CreateImageSDDRaft function.

0 Kudos