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()
Solved! Go to Solution.
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!
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!
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.
Hello this has been resolved in 2.1.0.3 version or you can use the newest 2.2.0 beta release