英文:
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))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论