1 回答

TA貢獻(xiàn)1878條經(jīng)驗 獲得超4個贊
您可以列出容器中的 blob,然后按 .json 擴展名過濾 json 文件blob.name
。
這是我的測試容器中的 blob:
這是我的Python代碼:
import os, uuid
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
try:
# environment variable into account.
connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
# Create the BlobServiceClient object which will be used to create a container client
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
# Create a unique name for the container
container_name = "test"
# Create the container
container_client = blob_service_client.get_container_client(container_name)
# List the blobs in the container
local_path = "./data"
blob_list = container_client.list_blobs()
for blob in blob_list:
if('.json' in blob.name) :
local_file_name = blob.name
blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)
download_file_path = os.path.join(local_path, local_file_name)
print("\nDownloading blob to \n\t" + local_path)
with open(download_file_path, "wb") as download_file:
download_file.write(blob_client.download_blob().readall())
print("\t" + blob.name)
except Exception as ex:
print('Exception:')
print(ex)
當(dāng)我運行代碼時,它將下載data.json和data2.json.
添加回答
舉報