我有一个container,名为test in azure storage。我想为此生成URL。它里面的文件目录如下所示:
test
-> annotate # This is a dir
-> file1.txt
-> file2.txt
-> images # This is a dir
-> file1.jpg
-> file2.jpg我想要生成URL,以便当访问它时,我可以下载完整的容器test,包括它里面的所有文件和目录。现在我已经这样做了,但是在这种方法中,我只是使用下面的代码下载blob:
account_name = "deeusblobstorage"
container_name = "rperodct"
blob_name = "face_1_7285.jpg"
account_key = "hMlIRXCjAomfDRfied8Y5FPwTVnWEkEDuVsw//CQtkiOdcFD/y5wUcxH9Ou7Ni+DtDQFwe23YbZ3Qia9gw=="
url = f"https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}"
sas_token = generate_blob_sas(
account_name=account_name,
account_key=account_key,
container_name=container_name,
blob_name=blob_name,
permission=AccountSasPermissions(read=True),
expiry=datetime.datetime.utcnow() + timedelta(hours=1)
)
url_with_sas = f"{url}?{sas_token}"
print(url_with_sas)在上面的代码中,我特别提到要下载的容器中的blob,然后生成url。但是,我们如何为容器生成url,以便可以下载容器中的所有文件和目录。谢谢
发布于 2022-09-13 12:30:12
,但是我们如何为容器生成url,以便可以下载容器中的所有文件和目录。
简单地说,您不能通过使用容器URL直接下载容器中的所有blobs。您需要做的是首先列出容器中的blobs,然后下载单个blobs。
为了列出容器中的blob,然后下载每个blob,您需要使用generate_container_sas方法在容器上生成一个SAS令牌。在您的SAS令牌中需要read和list权限。
获得SAS令牌后,首先列出blob,然后使用为容器获得的blob URL和SAS令牌为每个blob创建SAS。
https://stackoverflow.com/questions/73702754
复制相似问题