Install Library: azure-storage-file-share
https://pypi.org/project/azure-storage-file-share/
#Upload to Azure File Share
from azure.storage.fileshare import ShareFileClient
file_client = ShareFileClient.from_connection_string(conn_str="AZURE_STORAGE_CONNECTION_STRING", share_name="AZURE_STORAGE_FILE_SHARE_NAME", file_path="summary_uploaded.csv")
with open("/dbfs/tmp/summary_to_upload.csv", "rb") as source_file:
file_client.upload_file(source_file)
#Download from Azure File Share
file_client = ShareFileClient.from_connection_string(conn_str="AZURE_STORAGE_CONNECTION_STRING", share_name="AZURE_STORAGE_FILE_SHARE_NAME", file_path="summary_to_download.csv")
with open("/dbfs/tmp/summary_downloaded.csv", "wb") as file_handle:
data = file_client.download_file()
data.readinto(file_handle)
Next steps:
- Define a new secret key in Azure Key Vault for holding the value for ‘conn_str’ (AZURE_STORAGE_CONNECTION_STRING).
Key can be: az-storage-conn-string
- Define a new secret key in Azure Key Vault for holding the value for ‘share_name’ (AZURE_STORAGE_FILE_SHARE_NAME).
Key: az-storage-file-share
- Read both of these keys from key vault and avoid hard-coding.