Skip to content

Commit

Permalink
docs: Add docs for public buckets (#1625)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcus Kohlberg <78424526+marcuskohlberg@users.noreply.github.com>
  • Loading branch information
ekerfelt and marcuskohlberg authored Dec 9, 2024
1 parent 5bb2ad6 commit 785df61
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
25 changes: 25 additions & 0 deletions docs/go/primitives/object-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion docs/platform/infrastructure/infra.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
6 changes: 5 additions & 1 deletion docs/ts/primitives/object-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand Down

0 comments on commit 785df61

Please sign in to comment.