doutun9179
2019-06-24 22:45
浏览 281
已采纳

将文件放置到Golang中的Amazon S3后,如何获取文件URL?

File is uploaded successfully, and I want to return file url after uploading.

_, err := s3.New(s).PutObject(&s3.PutObjectInput{
    Bucket:               aws.String("bucket"),
    Key:                  aws.String(tempFileName),
    ACL:                  aws.String("public-read"), // could be private if you want it to be access by only authorized users
    Body:                 bytes.NewReader(buffer),
    ContentLength:        aws.Int64(int64(size)),
    ContentType:          aws.String(http.DetectContentType(buffer)),
    ContentDisposition:   aws.String("attachment"),
    ServerSideEncryption: aws.String("AES256"),
    StorageClass:         aws.String("INTELLIGENT_TIERING"),
})

I have checked amazon doc for PutObject function, but PutObjectOutput struct type But there is no uploaded file url in this structure.

How can I get file url? Is there other way to return uploaded file url in amazon s3 sdk as soon as upload success?

Thanks

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

2条回答 默认 最新

  • doujingdai5521 2019-06-24 23:55
    已采纳

    You can construct the URL as:

    https://BUCKETNAME.s3-REGIONNAME.amazonaws.com/KEY
    

    For example:

    https://my-bucket.s3-ap-southeast-2.amazonaws.com/foo/bar.txt
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题