From 785df61b79eb7d87c8d784853f543a2daf9374b3 Mon Sep 17 00:00:00 2001 From: Stefan Ekerfelt Date: Mon, 9 Dec 2024 17:15:16 +0100 Subject: [PATCH] docs: Add docs for public buckets (#1625) Co-authored-by: Marcus Kohlberg <78424526+marcuskohlberg@users.noreply.github.com> --- docs/go/primitives/object-storage.md | 25 +++++++++++++++++++++++++ docs/platform/infrastructure/infra.md | 2 +- docs/ts/primitives/object-storage.md | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/go/primitives/object-storage.md b/docs/go/primitives/object-storage.md index cb89dd6910..7ceeede3e2 100644 --- a/docs/go/primitives/object-storage.md +++ b/docs/go/primitives/object-storage.md @@ -205,6 +205,31 @@ if err != nil { } ``` +## Using Public Buckets + +Encore 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`: + +```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: + +```go +// 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 +``` +When self-hosting, see how to configure public buckets in the [infrastructure configuration docs](/docs/ts/self-host/configure-infra). + +When deploying with Encore Cloud it will automatically configure the bucket to be publicly accessible and [configure CDN](/docs/platform/infrastructure/infra#production-infrastructure) for optimal content delivery. + ### Using bucket references Encore uses static analysis to determine which services are accessing each bucket, diff --git a/docs/platform/infrastructure/infra.md b/docs/platform/infrastructure/infra.md index 0380780932..169c040b5c 100644 --- a/docs/platform/infrastructure/infra.md +++ b/docs/platform/infrastructure/infra.md @@ -89,7 +89,7 @@ Encore Cloud provisions production infrastructure resources using best-practice | **Compute:** | [Cloud Run](/docs/platform/infrastructure/gcp#google-cloud-run), [GKE](/docs/platform/infrastructure/gcp#google-kubernetes-engine) | [Fargate ECS](/docs/platform/infrastructure/aws#aws-fargate), [EKS](/docs/platform/infrastructure/aws#aws-eks) | | **SQL Databases:** | [GCP Cloud SQL](/docs/platform/infrastructure/gcp#databases), [Neon](/docs/platform/infrastructure/neon) | [Amazon RDS](/docs/platform/infrastructure/aws#databases), [Neon](/docs/platform/infrastructure/neon) | | **Pub/Sub:** | [GCP Pub/Sub](/docs/platform/infrastructure/gcp#pubsub) | [Amazon SQS & Amazon SNS](/docs/platform/infrastructure/aws#pubsub) | -| **Object Storage:** | [GCS](/docs/platform/infrastructure/gcp#object-storage) | [Amazon S3](/docs/platform/infrastructure/aws#object-storage) | +| **Object Storage:** | [GCS/Cloud CDN](/docs/platform/infrastructure/gcp#object-storage) | [Amazon S3/CloudFront](/docs/platform/infrastructure/aws#object-storage) | | **Caches:** | [GCP Memorystore (Redis)](/docs/platform/infrastructure/gcp#caching) | [Amazon ElastiCache (Redis)](/docs/platform/infrastructure/aws#caching) | | **Cron Jobs:** | Encore Cloud Managed | Encore Cloud Managed | Encore Cloud Managed | | **Secrets:** | [Secret Manager](/docs/platform/infrastructure/gcp#secrets-management) | [AWS Secrets Manager](/docs/platform/infrastructure/aws#se) | diff --git a/docs/ts/primitives/object-storage.md b/docs/ts/primitives/object-storage.md index 8a263b92ba..41fd9fef8c 100644 --- a/docs/ts/primitives/object-storage.md +++ b/docs/ts/primitives/object-storage.md @@ -113,7 +113,7 @@ For convenience there is also `exists` which returns a boolean indicating whethe const exists = await profilePictures.exists("my-image.jpeg"); ``` -## Using Public Buckets +## Configuring Public Buckets To configure a bucket to be publicly accessible, set the `public` property to `true` when creating the bucket. This allows objects in the bucket to be accessed via a public URL. @@ -126,8 +126,12 @@ export const publicProfilePictures = new Bucket("public-profile-pictures", { }); ``` +When self-hosting, see how to configure public buckets in the [infrastructure configuration docs](/docs/go/self-host/configure-infra). + When deploying with Encore Cloud it will automatically configure the bucket to be publicly accessible and [configure CDN](/docs/platform/infrastructure/infra#production-infrastructure) for optimal content delivery. +### Accessing Public Objects + Once a bucket is configured as public, you can access its objects using the `publicUrl` method. This method returns the public URL for the specified object. For example, to get the public URL of a profile picture: