From 04e571d43adff27f1715cd8d656dc4a023012b5d Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Tue, 19 Sep 2023 15:20:27 +0530 Subject: [PATCH] Fix file fetch in attachments failing for signed URLs. Closes #1499. --- internal/media/providers/s3/s3.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/media/providers/s3/s3.go b/internal/media/providers/s3/s3.go index bd90356..a05ecd8 100644 --- a/internal/media/providers/s3/s3.go +++ b/internal/media/providers/s3/s3.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "io/ioutil" + "net/url" "path/filepath" "strings" "time" @@ -107,10 +108,16 @@ func (c *Client) GetURL(name string) string { } // GetBlob reads a file from S3 and returns the raw bytes. -func (c *Client) GetBlob(url string) ([]byte, error) { +func (c *Client) GetBlob(uurl string) ([]byte, error) { + if p, err := url.Parse(uurl); err != nil { + uurl = filepath.Base(uurl) + } else { + uurl = filepath.Base(p.Path) + } + file, err := c.s3.FileDownload(simples3.DownloadInput{ Bucket: c.opts.Bucket, - ObjectKey: c.makeBucketPath(filepath.Base(url)), + ObjectKey: c.makeBucketPath(filepath.Base(uurl)), }) if err != nil { return nil, err