From c0521791db7985a4be3615ccde10920273524125 Mon Sep 17 00:00:00 2001 From: Roman Kredentser Date: Fri, 5 Jun 2020 00:03:12 +0300 Subject: [PATCH] s3: implement link sharing with PublicLink --- backend/s3/s3.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index c6201492c..306d2a17b 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -1959,6 +1959,20 @@ func (f *Fs) getMemoryPool(size int64) *pool.Pool { ) } +// PublicLink generates a public link to the remote path (usually readable by anyone) +func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration, unlink bool) (link string, err error) { + if _, err := f.NewObject(ctx, remote); err != nil { + return "", err + } + bucket, bucketPath := f.split(remote) + httpReq, _ := f.c.GetObjectRequest(&s3.GetObjectInput{ + Bucket: &bucket, + Key: &bucketPath, + }) + + return httpReq.Presign(time.Duration(expire)) +} + // ------------------------------------------------------------ // Fs returns the parent Fs