为Go中的aws-sdk-go-v2添加AWS S3的预签名URL过期时间

huangapple go评论79阅读模式
英文:

Adding Presign URL Expiration for AWS s3 in aws-sdk-go-v2 for Go

问题

这里有一个非常好的例子,展示了如何使用aws-sdk-go-v2创建预签名URL:链接

这个例子很好,但是我在设置过期时间时遇到了问题。我看到PresignOptions结构体有一个Expires字段,但我不确定如何设置它。

我还看到了WithPresignExpires方法,但是很遗憾,我不知道如何在这个例子中使用它。

能否在这里提供一个例子?我正在学习Go,但是有些东西我还没有掌握。

英文:

There is a very fine example of using the aws-sdk-go-v2 to create pre-signed URLs.

This works well but I'm stuck on setting the expiration time. I do see the PresignOptions struct has an Expires but I'm not certain how to do that.

I also see WithPresignExpires but alas, I also do not know how to use this given the example.

Can an example be provided here? I'm learning Go but something is just outside my grasp here.

答案1

得分: 3

似乎我可以将其设置为60分钟过期。

func GetPresignedURL(c context.Context, api S3PresignGetObjectAPI, input *s3.GetObjectInput) (*v4.PresignedHTTPRequest, error) {
	return api.PresignGetObject(c, input, s3.WithPresignExpires(3600*time.Second))
}
英文:

Seems I can do this for 60 minute expiration.

func GetPresignedURL(c context.Context, api S3PresignGetObjectAPI, input *s3.GetObjectInput) (*v4.PresignedHTTPRequest, error) {
	return api.PresignGetObject(c, input, s3.WithPresignExpires(3600*time.Second))
}

huangapple
  • 本文由 发表于 2021年10月20日 03:58:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/69636990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定