Переглянути джерело

Add explicit `public-read` ACL to public S3 uploads. Closes #496.

Kailash Nadh 3 роки тому
батько
коміт
7aa850824c
1 змінених файлів з 8 додано та 3 видалено
  1. 8 3
      internal/media/providers/s3/s3.go

+ 8 - 3
internal/media/providers/s3/s3.go

@@ -61,7 +61,7 @@ func NewS3Store(opt Opt) (media.Store, error) {
 // Put takes in the filename, the content type and file object itself and uploads to S3.
 // Put takes in the filename, the content type and file object itself and uploads to S3.
 func (c *Client) Put(name string, cType string, file io.ReadSeeker) (string, error) {
 func (c *Client) Put(name string, cType string, file io.ReadSeeker) (string, error) {
 	// Upload input parameters
 	// Upload input parameters
-	upParams := simples3.UploadInput{
+	p := simples3.UploadInput{
 		Bucket:      c.opts.Bucket,
 		Bucket:      c.opts.Bucket,
 		ContentType: cType,
 		ContentType: cType,
 		FileName:    name,
 		FileName:    name,
@@ -70,8 +70,13 @@ func (c *Client) Put(name string, cType string, file io.ReadSeeker) (string, err
 		// Paths inside the bucket should not start with /.
 		// Paths inside the bucket should not start with /.
 		ObjectKey: c.makeBucketPath(name),
 		ObjectKey: c.makeBucketPath(name),
 	}
 	}
-	// Perform an upload.
-	if _, err := c.s3.FileUpload(upParams); err != nil {
+
+	if c.opts.BucketType == "public" {
+		p.ACL = "public-read"
+	}
+
+	// Upload.
+	if _, err := c.s3.FileUpload(p); err != nil {
 		return "", err
 		return "", err
 	}
 	}
 	return name, nil
 	return name, nil