Browse Source

Fix file fetch in attachments failing for signed URLs. Closes #1499.

Kailash Nadh 1 year ago
parent
commit
04e571d43a
1 changed files with 9 additions and 2 deletions
  1. 9 2
      internal/media/providers/s3/s3.go

+ 9 - 2
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