我必须将一组文件夹上传到中的一个专用容器中。我发现了以下内容:https://github.com/rahulbagal/upload-file-azure-sas-url,但它只是用于使用专用的Blob上传文件,而且工作非常完美。
是否有任何类似的解决方案可以管理文件夹上载而不是文件上载?
谢谢你的进阶
发布于 2021-04-23 08:57:41
1.请尝试使用以下代码:
import os
from azure.storage.blob import BlobServiceClient
account_url = "https://<storage-account-name>.blob.core.windows.net/"
sas_token = "<your-sas-token>"
blob_service_client = BlobServiceClient(account_url, sas_token)
container_name = "<your-container-name>"
container_client = blob_service_client.get_container_client(container_name)
local_path = "<your-folder-path>"
folder_name = "<your-folder-name>"
for files in os.listdir(local_path):
with open(os.path.join(local_path,files), "rb") as data:
blob_client = blob_service_client.get_blob_client(container=container_name, blob= folder_name + "/" + files)
blob_client.upload_blob(data)2.或您可以使用azcopy上载文件夹:
例如:
azcopy copy '<folder-path>' 'https://<account-name>.blob.core.windows.net/<container-name>?<sas-token>' --recursive有关更多细节,您可以参考此正式文件。
https://stackoverflow.com/questions/67225885
复制相似问题