Dec 10, 20243 min read

Public Object Storage Buckets + R2 Support

Launch Week Day 2

It's Day 2 of Launch Week and we're back with another launch...

Encore.go and Encore.ts now support Public Object Storage Buckets

Today we're launching Public Buckets, an extension of our recently released Object Storage primitive for Encore.go and Encore.ts. This feature simplifies working with public-facing file storage directly in your application code and adds CDN support for optimal content delivery.

How Object Storage works in Encore

Encore lets you integrate infrastructure as type-safe objects in your application code. Whether you're creating a database, a Pub/Sub topic, or an Object Storage bucket, it's as easy as writing a few lines of code.

Example

To create a bucket in Encore.go you define it as a constant within a service:

package user import "encore.dev/storage/objects" var ProfilePictures = objects.NewBucket("profile-pictures", objects.BucketConfig{ Versioned: false, })

That's it! Encore sets up the infrastructure automatically when you run your app locally.

For manual cloud deployments, you just provide a runtime configuration and Encore handles the rest.

Using Public Buckets for simple file sharing

Encore now supports creating public buckets where objects can be accessed directly via HTTP/HTTPS without authentication. This is useful for serving static assets like images, videos, or other public files.

To create a public bucket, set Public: true in the BucketConfig.

Here's how to do it in Encore.go:

var PublicAssets = objects.NewBucket("public-assets", objects.BucketConfig{ Public: true, })

Once configured as public, you can get the public URL for any object using the PublicURL method:

// Get the public URL for an object url := PublicAssets.PublicURL("path/to/image.jpg") // The URL can be used directly or shared publicly fmt.Println(url) // e.g. https://assets.example.com/path/to/image.jpg

For manual cloud deployments, you just need to provide a provide a base url in the runtime configuration, and Encore handles the rest.

When deploying with the Encore platform it will automatically configure the bucket to be publicly accessible and configure CDN for optimal content delivery, using:

With Public Buckets, Encore makes managing object storage and public file access simple, powerful, and fully type-safe.

Simple testing in the Development Dashboard

Encore's Development Dashboard makes testing very simple. Call your endpoints, such as the list endpoint, to view and trace requests and get detailed insights. Traces provide insights including file uploads and bucket queries, helping you debug and optimize.

The Encore platform now supports Cloudflare R2

The Encore platform now supports Cloudflare R2 as an object storage provider. R2 can often be a cheaper alternative to AWS S3. This is great for anyone looking to save costs on object storage, while getting access to a global CDN.

To use Cloudflare R2, select it on the Create environment page in the Encore platform dashboard. If you have an existing environment, contact us to enable it. (Self-serve is coming soon!)

Join the Live stream

Watch today's live stream at 14:00 CET for an in-depth walkthrough and a live Q&A session.

Try it yourself

If you're already using Encore, update using encore version update.

If you're new to Encore, install using the instructions below and then create an example app using encore app create.

Install Encore
brew install encoredev/tap/encore &&
encore app create
Copy

If you have questions or just want to hang out with other Encore developers, join our community on Discord.

Encore

This blog is presented by Encore, automated infrastructure for humans and agents. Let agents build and validate features with real infrastructure in the dev loop, from local dev to production in your cloud on AWS/GCP.

Like this article? Get future ones straight to your mailbox.

You can unsubscribe at any time.