Select to view content in your preferred language

export item not respecting file_name parameter

618
3
Jump to solution
06-22-2023 01:08 AM
Labels (1)
MartinPeak
New Contributor II

when i run the below snippet, i expect to have a downloaded file "filegdb.zip", but what comes out is a file called "temp_export.zip". The file_name parameter of the export_item.download function is not being respected. It was working correctly untill very recently. Anyone else experiencing this or know what's going on?

from arcgis.gis import GIS

gis = GIS(username="username",password="password")

item_id = "XXXXXXXXXXXXX"

file_name= "filegdb.zip"
download_folder = "C:/temp_folder/"
output_format="File Geodatabase"
item = gis.content.get(item_id)

export_item = item.export(title="temp_export", export_format=output_format)
export_item.download(save_path=download_folder, file_name=file_name)
export_item.delete()

 

0 Kudos
1 Solution

Accepted Solutions
ITAdmin
New Contributor II

Hi @MartinPeak ,

The file_name parameter of the export_item.download function is not being respected. This is a known issue with the ArcGIS API for Python, and there is a workaround that you can use.

The workaround is to use the with statement to open the downloaded file in binary mode. This will ensure that the file is saved with the correct name.

     from arcgis.gis import GIS

      gis = GIS(username="username", password="password")

      item_id = "XXXXXXXXX"

      file_name = "filegdb.zip"
     download_folder = "C:/temp_folder/"
     output_format = "File Geodatabase"
     item = gis.content.get(item_id)

     export_item = item.export(title="temp_export", export_format=output_format)

     with open(os.path.join(download_folder, file_name), "wb") as f:
     f.write(export_item.download())export_item.delete()

 

 

This code will create a file called "filegdb.zip" in the C:/temp_folder/ directory.

The issue with the file_name parameter is that it is not being used by the ArcGIS API for Python to set the name of the downloaded file. Instead, the name of the downloaded file is set by the export_item.download() function. This function uses the title of the export item as the name of the downloaded file.

The workaround with the with statement ensures that the file is saved with the correct name by opening the file in binary mode and writing the contents of the downloaded file to the file.

I hope this helps!

View solution in original post

0 Kudos
3 Replies
ITAdmin
New Contributor II

Hi @MartinPeak ,

The file_name parameter of the export_item.download function is not being respected. This is a known issue with the ArcGIS API for Python, and there is a workaround that you can use.

The workaround is to use the with statement to open the downloaded file in binary mode. This will ensure that the file is saved with the correct name.

     from arcgis.gis import GIS

      gis = GIS(username="username", password="password")

      item_id = "XXXXXXXXX"

      file_name = "filegdb.zip"
     download_folder = "C:/temp_folder/"
     output_format = "File Geodatabase"
     item = gis.content.get(item_id)

     export_item = item.export(title="temp_export", export_format=output_format)

     with open(os.path.join(download_folder, file_name), "wb") as f:
     f.write(export_item.download())export_item.delete()

 

 

This code will create a file called "filegdb.zip" in the C:/temp_folder/ directory.

The issue with the file_name parameter is that it is not being used by the ArcGIS API for Python to set the name of the downloaded file. Instead, the name of the downloaded file is set by the export_item.download() function. This function uses the title of the export item as the name of the downloaded file.

The workaround with the with statement ensures that the file is saved with the correct name by opening the file in binary mode and writing the contents of the downloaded file to the file.

I hope this helps!

0 Kudos
MartinPeak
New Contributor II

Thank you! That will work. Where can i find out updates about the known issue and when it gets resolved? I'd prefer to go back to the original solution as its cleaner.

0 Kudos
NanaeAubry
Esri Contributor

Hello this has been resolved in 2.1.0.3 version or you can use the newest 2.2.0 beta release

0 Kudos