![](/img/trans.png)
[英]Python Azure SDK: Using list_blobs to get more than 5.000 Results
[英]Azure SDK for Python: How to limit results in list_blobs()?
如何限制從ContainerClient.list_blobs()
方法返回的 blob 數量?
Azure Blob 服務 RESP API 文檔提到了一個maxresults
參數,但它似乎不受list_blobs(maxresults=123)
的尊重。
itertools.islice
和 results_per_page 參數(轉換為results_per_page
maxresults
參數)的組合可以解決問題:
import itertools
service: BlobServiceClient = BlobServiceClient.from_connection_string(cstr)
cc = service.get_container_client("foo")
n = 42
for b in itertools.islice(cc.list_blobs(results_per_page=n), n):
print(b.name)
請在ItemPaged class上使用 by_page()
pages = ContainerClient.list_blobs(maxresults=123).by_page()
first_page = next(pages)
items_in_page = list(a_page) #this will give you 123 results on the first page
second_page = next(pages) # it will throw exception if there's no second page
items_in_page = list(a_page) #this will give you 123 results on the second page
SDK 目前無法做到這一點。 maxresults
參數實際上意味着“每頁的最大結果”; 如果你有比這更多的 blob, list_blobs
將多次調用 REST API 直到列表完成。
您可以直接調用 API 並忽略第一個頁面之后的頁面,但這需要您處理身份驗證的詳細信息、解析響應等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.