From 72d22d40ef3395f42fd5e76d76896c5e5524df0a Mon Sep 17 00:00:00 2001 From: Rohan Verma Date: Mon, 16 Jan 2023 15:49:21 +0530 Subject: [PATCH] fix: check public URL before presigned URL generation (#1148) Fixes #1141 --- internal/media/providers/s3/s3.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/media/providers/s3/s3.go b/internal/media/providers/s3/s3.go index c9eb8b95..3453583c 100644 --- a/internal/media/providers/s3/s3.go +++ b/internal/media/providers/s3/s3.go @@ -81,8 +81,9 @@ func (c *Client) Put(name string, cType string, file io.ReadSeeker) (string, err // Get accepts the filename of the object stored and retrieves from S3. func (c *Client) Get(name string) string { - // Generate a private S3 pre-signed URL if it's a private bucket. - if c.opts.BucketType == "private" { + // Generate a private S3 pre-signed URL if it's a private bucket, and there + // is no public URL provided. + if c.opts.BucketType == "private" && c.opts.PublicURL == "" { u := c.s3.GeneratePresignedURL(simples3.PresignedInput{ Bucket: c.opts.Bucket, ObjectKey: c.makeBucketPath(name), @@ -93,7 +94,8 @@ func (c *Client) Get(name string) string { return u } - // Generate a public S3 URL if it's a public bucket. + // Generate a public S3 URL if it's a public bucket or a public URL is + // provided. return c.makeFileURL(name) }