
Description
Store unstructured files in Encore.ts using `Bucket` from `encore.dev/storage/objects` — uploads, images, documents, blobs.
SKILL.md
Encore Object Storage
Instructions
A Bucket is a logical store for files. Encore provisions the underlying object storage (S3 on AWS, GCS on GCP, in-memory locally). Declare buckets at package level.
import { Bucket } from "encore.dev/storage/objects";
// Private bucket (default)
export const uploads = new Bucket("user-uploads", {
versioned: false, // Set to true to keep multiple versions
});
// Public bucket — files accessible via public URL
export const publicAssets = new Bucket("public-assets", {
public: true,
versioned: false,
});
Operations
// Upload
const attrs = await uploads.upload("path/to/file.jpg", buffer, {
contentType: "image/jpeg",
});
// Download
const data = await uploads.download("path/to/file.jpg");
// Existence check
const exists = await uploads.exists("path/to/file.jpg");
// Attributes (size, content type, ETag)
const meta = await uploads.attrs("path/to/file.jpg");
// Delete
await uploads.remove("path/to/file.jpg");
// List
for await (const entry of uploads.list({})) {
console.log(entry.key, entry.size);
}
// Public URL (only for public buckets)
const url = publicAssets.publicUrl("image.jpg");
Signed URLs
Generate temporary URLs so clients can upload/download directly without going through your service:
const uploadUrl = await uploads.signedUploadUrl("user-uploads/avatar.jpg", { ttl: 7200 });
const downloadUrl = await uploads.signedDownloadUrl("documents/report.pdf", { ttl: 7200 });
Bucket References
Pass bucket access to other code with a specific permission set:
import { Uploader, Downloader } from "encore.dev/storage/objects";
const uploaderRef = uploads.ref<Uploader>();
const downloaderRef = uploads.ref<Downloader>();
// Permission types: Downloader, Uploader, Lister, Attrser, Remover,
// SignedDownloader, SignedUploader, ReadWriter
Errors
ObjectNotFound— object doesn't existPreconditionFailed— upload preconditions not met (e.g.setIfNotExists)ObjectsError— base error type
Guidelines
- Declare buckets at package level.
- Default to private buckets; opt into
public: trueonly for assets meant for unauthenticated download. - Use signed URLs for browser uploads/downloads instead of streaming through your service.
- Use bucket references when passing access to helpers — they encode the permission contract in the type system.
More skills from the skills repository
View all 28 skillsencore-api
build type-safe APIs with Encore
Apr 6API DevelopmentEncoreTypeScriptencore-auth
implement Encore.ts authentication
Apr 6AuthEncoreTypeScriptencore-cache
cache data in Redis with Encore.ts
May 16BackendCachingEncoreRedis +1encore-code-review
review Encore.ts code
Apr 6Code ReviewEncoreTypeScriptencore-cron
schedule recurring jobs in Encore.ts
May 16AutomationBackendEncoreScheduling +1encore-database
build Encore databases
Apr 6DatabaseEncoreORMTypeScript
More from Encore
View publisherencore-frontend
connect frontend to Encore backend
skills
Apr 6EncoreFrontendNext.jsReactencore-getting-started
build and run applications with Encore.ts
skills
Apr 6API DevelopmentBackendEncoreLocal Development +2encore-go-api
build APIs with Encore Go
skills
Apr 6API DevelopmentEncoreGoencore-go-auth
implement authentication with Encore Go
skills
Apr 6AuthBackendEncoreGoencore-go-bucket
store files in Encore Go buckets
skills
May 16BackendEncoreFile StorageGo +1