From c39e337bb71994c00e6c5132a5d561cc552fcbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=9D=B0?= Date: Wed, 10 Jul 2024 17:38:54 +0800 Subject: [PATCH] provider/s3: SignedPUT. --- providers/s3/s3.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/providers/s3/s3.go b/providers/s3/s3.go index dad89e6..2ca0cfd 100644 --- a/providers/s3/s3.go +++ b/providers/s3/s3.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" "testing" + "time" "github.com/efficientgo/core/logerrcapture" "github.com/go-kit/log" @@ -651,3 +652,16 @@ func NewTestBucketFromConfig(t testing.TB, location string, c Config, reuseBucke func ContextWithSSEConfig(ctx context.Context, value encrypt.ServerSide) context.Context { return context.WithValue(ctx, sseConfigKey, value) } + +// SignedPUT Returns a presigned URL to upload an object without credentials. URL can have a maximum expiry of upto 7days or a minimum of 1sec. +func (b *Bucket) SignedPUT( + ctx context.Context, + objectKey string, + expiry time.Time, +) (string, error) { + u, err := b.client.PresignedPutObject(ctx, b.name, objectKey, expiry.Sub(time.Now())) + if err != nil { + return "", err + } + return u.String(), nil +}