使用 python 将 CSV 文件上传到 Microsoft Azure 存储帐户

2024-06-19

我正在尝试上传一个.csv使用 python 将文件写入 Microsoft Azure 存储帐户。我已经发现C-sharp https://blogs.msdn.microsoft.com/jmstall/2012/08/03/converting-between-azure-tables-and-csv/将数据写入 blob 存储的代码。但是,我不知道C#语言。我需要上传.csv使用 python 文件。

有没有 python 将 CSV 文件的内容上传到 Azure 存储的示例?


我找到了使用的解决方案this https://learn.microsoft.com/en-us/azure/storage/storage-python-how-to-use-blob-storage参考链接。我的以下代码完美适用于上传中 and 下载 .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')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 python 将 CSV 文件上传到 Microsoft Azure 存储帐户 的相关文章

随机推荐