使用 python 将 CSV 文件上传到 Microsoft Azure 存储帐户
问题描述
我正在尝试使用 python 将 .csv
文件上传到 Microsoft Azure 存储帐户.我发现 C-清晰的 代码将数据写入 blob 存储.但是,我不懂 C#
语言.我需要使用 python 上传 .csv
文件.
I am trying to upload a .csv
file into Microsoft Azure storage account using python. I have found C-sharp code to write a data to blob storage. But, I don't know C#
language. I need to upload .csv
file using python.
是否有 python 将 CSV 文件内容上传到 Azure 存储的示例?
解决方案
我使用 this 参考链接.我的以下代码完美适用于 uploading 和 downloading .csv
文件.
I found the solution using this reference link. My following code perfectly work for uploading and downloading .csv
file.
#!/usr/bin/env python
from azure.storage.blob import BlockBlobService
from azure.storage.blob import ContentSettings
block_blob_service = BlockBlobService(account_name='<myaccount>', account_key='mykey')
block_blob_service.create_container('mycontainer')
#Upload the CSV file to Azure cloud
block_blob_service.create_blob_from_path(
'mycontainer',
'myblockblob.csv',
'test.csv',
content_settings=ContentSettings(content_type='application/CSV')
)
# Check the list of blob
generator = block_blob_service.list_blobs('mycontainer')
for blob in generator:
print(blob.name)
# Download the CSV file From Azure storage
block_blob_service.get_blob_to_path('mycontainer', 'myblockblob.csv', 'out-test.csv')
相关文章