pub fn list(
ctx: &Ctx,
prefix: &str,
cursor: Option<&str>,
limit: u32,
) -> impl Future<Output = Result<Listing>> + Send + use<>Expand description
Lists one page of the objects whose key starts with prefix, in key order, with their size, type and upload time.
Pass None as cursor for the first page, then the returned
Listing::cursor until it is None. limit is clamped to 1..=1000;
a page may hold fewer objects even when more follow (R2 caps the
metadata it returns), so rely on the cursor, not the count.
Free plan: one R2 class A operation per call, like an upload (1M free per month), and decoding 1,000 entries takes a few ms of the 10 ms of CPU: list in scheduled tasks or admin pages, never on every request.
§Errors
Error::Internal (500) when the STORAGE
binding is missing or R2 fails.
§Examples
use ocre::{Ctx, Result, storage};
// Total size of the exports, 1,000 keys (one class A operation) at a time.
async fn exports_size(ctx: &Ctx) -> Result<u64> {
let (mut total, mut cursor) = (0, None);
loop {
let page = storage::list(ctx, "exports/", cursor.as_deref(), 1000).await?;
total += page.objects.iter().map(|object| object.size).sum::<u64>();
cursor = page.cursor;
if cursor.is_none() {
return Ok(total);
}
}
}