It's Day 2 of Launch Week and we're back with another launch...
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.
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.
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.
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 Encore Cloud 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.
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.
Encore Cloud 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 Cloud dashboard. If you have an existing environment, contact us to enable it. (Self-serve is coming soon!)
Watch today's live stream at 14:00 CET for an in-depth walkthrough and a live Q&A session.
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
.
$ brew install encoredev/tap/encore
If you have questions or just want to hang out with other Encore developers, join our community on Discord.