簡體   English   中英

我們如何使用 Python 將文件加載到 Azure Blob 存儲或 Azure 數據湖存儲?

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

我對 Azure 比較陌生。我想弄清楚如何使用 Python 將文件加載到 Azure 存儲帳戶,例如數據湖或 Blob 存儲。 我從以下兩個 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/storage-quickstart-blobs-python

也許我從這些資源中遺漏了一些東西,或者它們不適合我正在嘗試做的事情。 我只是想讓一個簡單的例子起作用,這樣我就可以開始更好地理解這個過程。 我想執行以下任一操作。

  1. 將文件從我的桌面復制到 Azure Blob 存儲或數據湖存儲

  2. 從 URL 下載文件並將其保存到 Azure Blob Storage 或 Data Lake Storage

我想從 Azure 運行 Python,所以我希望代碼在“Runbook”中運行。 如上所述,我如何做第 1 項或第 2 項,或者最好同時執行第 1 項和第 2 項?

您需要在您的自動化帳戶中添加azure_storage_blob python package

然后,您可以使用下面的 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM