Expand description
Object storage buckets. Declared at module scope; resolved from the runtime on use.
use encore::objects::Bucket;
static UPLOADS: Bucket = Bucket::new("uploads");
static AVATARS: Bucket = Bucket::new("avatars").public().versioned();Every operation is a method of the Bucket — upload, download,
list, attrs, remove, … — named as in Encore’s TypeScript and Go SDKs.
That is what lets Encore grant each service exactly the permissions it
uses: the operation is visible at the call, so the parser can read it.
§References
For the same reason, a bucket cannot be passed around as a value. To hand
it to other code, make a BucketRef, which grants only the permissions
its type argument names:
use encore::objects::{perms, Bucket, Uploader};
static UPLOADS: Bucket = Bucket::named("uploads");
// Library code asks for the permissions it needs, as traits.
async fn save(bucket: &impl Uploader, key: &str) -> Result<(), encore::Error> {
bucket.upload(key, b"hello".to_vec()).await?;
Ok(())
}
async fn greet() -> Result<(), encore::Error> {
save(&UPLOADS.reference::<perms::Uploader>(), "greeting.txt").await
}The permissions are one of the perms, or a tuple of them
((perms::Uploader, perms::Lister)). Each has a trait of the same name
here, with the methods it grants. Library code takes the traits —
&impl Uploader, &(impl Uploader + Lister) — so it works with any
reference that grants them, and can be tested against a fake.
Modules§
- perms
- The permissions a
BucketRefcan grant, as types for its type argument. Each has a trait of the same name inobjects, with the methods it grants.
Structs§
- Attrs
Options - Re-exported option and result types of the bucket operations.
- Bucket
- An object-storage bucket.
- Bucket
Ref - A reference to a
Bucketthat grants only the permissionsP, made byBucket::reference.Copy, and free to pass to other code. - Byte
Range - Re-exported option and result types of the bucket operations. A contiguous byte range within an object.
- Download
- The contents of an object, as they arrive: returned by
Bucket::download_stream. Take them chunk by chunk withDownload::next— or as aStream— all at once withDownload::bytes, or as anAsyncReadwithDownload::into_async_read. - Download
Options - Re-exported option and result types of the bucket operations.
- Exists
Options - Re-exported option and result types of the bucket operations.
- List
Entry - Re-exported option and result types of the bucket operations.
- List
Iterator - The objects of a bucket, as they are listed: returned by
Bucket::list. Take them one at a time withListIterator::next, or as aStream. - List
Options - Re-exported option and result types of the bucket operations.
- Object
Attrs - Re-exported option and result types of the bucket operations.
- Remove
Options - Re-exported option and result types of the bucket operations.
- Signed
Download Url - A URL through which anyone holding it can download an object, made by
Bucket::signed_download_url. - Signed
Upload Url - A URL through which anyone holding it can upload an object, made by
Bucket::signed_upload_url. - Signed
UrlOptions - Options for a signed URL.
- Upload
Options - Re-exported option and result types of the bucket operations.
- Upload
Preconditions - Re-exported option and result types of the bucket operations.
Traits§
- Attrser
- Read objects’ attributes, and whether they exist. Implemented by a
BucketRefgrantingperms::Attrser. - Bucket
Perms - A set of bucket permissions: one of the
perms, or a tuple of them, which grants what any of its members does. Sealed: the SDK’s permissions are the only ones. - Downloader
- Download objects. Implemented by a
BucketRefgrantingperms::Downloader. - Lister
- List objects. Implemented by a
BucketRefgrantingperms::Lister. - Public
Urler - Resolve objects’ public URLs. Implemented by a
BucketRefgrantingperms::PublicUrler. - Read
Writer - Every permission but
PublicUrler. Implemented by whatever implements them all, such as aBucketRefgrantingperms::ReadWriter. - Remover
- Remove objects. Implemented by a
BucketRefgrantingperms::Remover. - Signed
Downloader - Make signed download URLs. Implemented by a
BucketRefgrantingperms::SignedDownloader. - Signed
Uploader - Make signed upload URLs. Implemented by a
BucketRefgrantingperms::SignedUploader. - Uploader
- Upload objects. Implemented by a
BucketRefgrantingperms::Uploader.