2017-10-04 22:16
浏览 559

如何在Golang中从AWS S3获取资源URL

I need to get public permanent (not signed) URL of a resource using golang and official aws go sdk. In Java AWS S3 SDK there's a method called getResourceUrl() what's the equivalent in go?

图片转代码服务由CSDN问答提供 功能建议

我需要使用golang和官方AWS转到sdk 。 在Java AWS S3 SDK中,有一种名为 getResourceUrl() 到底有什么用?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxianji6181 2017-10-04 22:40

    This is how you get presigned URLs using the go sdk:

    func GetFileLink(key string) (string, error) {
        svc := s3.New(some params)
        params := &s3.GetObjectInput{
            Bucket: aws.String(a bucket name),
            Key:    aws.String(key),
        req, _ := svc.GetObjectRequest(params)
        url, err := req.Presign(15 * time.Minute) // Set link expiration time
        if err != nil {
            global.Log("[AWS GET LINK]:", params, err)
        return url, err

    If what you want is just the URL of a public access object you can build the URL yourself:


    Where is something like us-east-2. So using go it will be something like:

    url := ""
    url = fmt.Sprintf(url, "us-east-2", "my-bucket-name", "some-file.txt")

    Here is a list of all the available regions for S3.

    解决 无用
    打赏 举报

相关推荐 更多相似问题