简体   繁体   English

我们如何使用 Python 将文件加载到 Azure Blob 存储或 Azure 数据湖存储?

[英]How can we use Python to load files into Azure Blob Storage or Azure Data Lake Storage?

I am relatively new to Azure. I am trying to figure out how to use Python to load files into an Azure storage account, such as Data Lake or Blob Storage.我对 Azure 比较陌生。我想弄清楚如何使用 Python 将文件加载到 Azure 存储帐户,例如数据湖或 Blob 存储。 I read the info from the following two URLs, and I am stuck about how to proceed.我从以下两个 URL 中读取了信息,但我不知道如何继续。

https://learn.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-python https://learn.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-python

https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python

Maybe I missed something from those resource, or they are not right for what I am trying to do.也许我从这些资源中遗漏了一些东西,或者它们不适合我正在尝试做的事情。 I just want to get a simple example working so I can start to understand the process better.我只是想让一个简单的例子起作用,这样我就可以开始更好地理解这个过程。 I would like to do either of the following.我想执行以下任一操作。

  1. copy a file from my desktop to Azure Blob Storage or Data Lake Storage将文件从我的桌面复制到 Azure Blob 存储或数据湖存储

  2. download a file from a URL and save it to Azure Blob Storage or Data Lake Storage从 URL 下载文件并将其保存到 Azure Blob Storage 或 Data Lake Storage

I want to run Python from Azure, so I want the code to run in a 'Runbook'.我想从 Azure 运行 Python,所以我希望代码在“Runbook”中运行。 How can I do either item 1 or 2, as described above, or ideally both 1 and 2?如上所述,我如何做第 1 项或第 2 项,或者最好同时执行第 1 项和第 2 项?

You need to add the azure_storage_blob python package in your automation account您需要在您的自动化帐户中添加azure_storage_blob python package

Then, you can use the python code below to upload file to azure blob storage from a URL:然后,您可以使用下面的 python 代码将文件从 URL 上传到 azure blob 存储:

from azure.storage.blob import BlobServiceClient
connect_str = "StorageAccountConnectString"
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
destination_blob = blob_service_client.get_blob_client("ContainerName","BlobName")
destination_blob.start_copy_from_url("URL")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 dbt 将镶木地板文件从 Azure Data Lake Gen2/Azure Blob 存储加载到专用池? - How to load parquet files from Azure Data Lake Gen2/Azure Blob Storage to Dedicated pool using dbt? 如何使用 Airflow 将 CSV 文件从 Azure Data Lake/Blob 存储传输到 PostgreSQL 数据库 - How to transfer a CSV file from Azure Data Lake/Blob Storage to PostgreSQL database with Airflow 我们如何在 Azure 中运行标准的 Python 脚本并将文件保存到数据湖? - How can we run a standard Python script in Azure and save files to a Data Lake? 将最新的文件夹从 azure blob 存储加载到 azure 数据工厂 - Load the latest folder from azure blob storage to azure data factory 如何创建到 Azure 数据湖存储到 API 的连接? - How to create a connection to Azure data lake storage to API? Azure Data Lake Gen2 存储帐户 blob 与 adf 选择 - Azure Data Lake Gen2 Storage Account blob vs adf choice 如何使用 Python 和 Azure 函数在 Azure 存储容器中创建 blob - How to create a blob in an Azure Storage Container using Python & Azure Functions 我们如何使用 spark 和 scala 在 azure blob 存储中上传 parquet 文件? - how we can upload parquet file in azure blob storage using spark and scala? 如何在只有存储 Blob 数据贡献者角色的 Azure 存储资源管理器中打开存储容器? - How to open Storage Container in Azure Storage Explorer w/ only Storage Blob Data Contributor Role? Azure 逻辑应用程序如何将多个 JSON 文件合并到 Blob 存储 - Azure Logic Apps how to combine multiple JSON files to Blob storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM