我有一個查詢可以獲取 S3 存盤桶中的所有專案,如果該存盤桶中有很多專案,則加載需要很長時間。
bucket.objects(prefix: 'path/to/items').collect(&:key)
根據docs,我看到可以限制該提取中的專案數量。
bucket.objects(prefix: 'path/to/items').limit(10).collect(&:key)
但是,我沒有看到此函式的任何偏移引數。知道如何使用它進行分頁,以便加載前幾個結果不需要很長時間嗎?
uj5u.com熱心網友回復:
AWS在此處提供了一些示例來說明如何做到這一點。聽起來您應該能夠在回傳每個頁面時呼叫.each它bucket.objects(prefix: 'path/to/items')來處理它。
自動分頁:
s3 = Aws::S3::Client.new
s3.list_objects(bucket: 'aws-sdk').each do |response|
puts response.contents.map(&:key)
end
手動分頁:
s3 = Aws::S3::Client.new
# Get the first page of data
response = s3.list_objects(bucket: 'aws-sdk')
# Get additional pages
while response.next_page? do
response = response.next_page
# Use the response data here...
puts response.contents.map(&:key)
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/452366.html
