Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use signed URLs when using AWS S3 #7

Open
philiplb opened this issue Nov 4, 2018 · 1 comment
Open

Unable to use signed URLs when using AWS S3 #7

philiplb opened this issue Nov 4, 2018 · 1 comment

Comments

@philiplb
Copy link

philiplb commented Nov 4, 2018

Hi,
I'm using AWS S3 as storage provider like this:

import(
	"github.com/qor/oss/s3"
	awss3 "github.com/aws/aws-sdk-go/service/s3"
)

s3Client := s3.New(&s3.Config{
	AccessID:  ...,
	AccessKey: ...,
	Region:    ...,
	Bucket:    ...,
	ACL:       awss3.BucketCannedACLPrivate,
})

So I don't want to have the uploaded files public. But now the Adminpanel calls GetURL and runs into https://github.com/qor/oss/blob/master/s3/s3.go#L217 where the endpoint is != "" but automatically set to the S3 endpoint.

My current workaround doesn't feel optimal:

type S3Client struct {
	*s3.Client
}

// GetURL get public accessible URL
func (client S3Client) GetURL(path string) (url string, err error) {
	if client.Config.ACL == awss3.BucketCannedACLPrivate || client.Config.ACL == awss3.BucketCannedACLAuthenticatedRead {
		getResponse, _ := client.S3.GetObjectRequest(&awss3.GetObjectInput{
			Bucket: aws.String(client.Config.Bucket),
			Key:    aws.String(client.ToRelativePath(path)),
		})

		return getResponse.Presign(1 * time.Hour)
	}

	return path, nil
}

....

oss.Storage = S3Client{Client: s3Client}

Note the removed check for client.Endpoint == "".

Is there anything I'm missing here? Or have I found a bug?

@sergolius
Copy link

Have you tried to define Endpoint as a slash?

s3Client := s3.New(&s3.Config{
	...
	Endpoint:  "/",
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants