dquv73115 2018-03-27 22:37
浏览 322
已采纳

使用AWS开发工具包Go的完整URI从S3下载文件

The examples I've seen for downloading a file from S3 using the AWS SDK for Go are of the form:

downloader := s3manager.NewDownloader(session, /* other args */)

s3object := &s3.GetObjectInput{
    Bucket: aws.String(myBucket),
    Key: aws.String(myKey),
}

bytesDownloaded, err := downloader.Download(myFile, s3object)

That is, one uses the bucket and key to specify the file. But what if I already have the full URI of the file on S3? E.g.:

https://s3.us-west-2.amazonaws.com/myBucket/myKey

Is there a way using the SDK to specify the file to download using the URL directly?

No, the bucket is not public. In the SDK, I'm also setting the access and secret keys (elided from the example code).

Lastly, if it's simply not possible to do what I'm asking via the SDK, that's an acceptable (though not desired) answer.

  • 写回答

4条回答 默认 最新

  • doushifen4060 2018-03-28 02:07
    关注

    There is no way to do what you want. The only ways to get a private object are:

    1. Use the bucket and key to download the file
    2. Generate a presigned URL an do an hhtp.Get on that URL (to generate the presigned URL you need the bucket and key)

    If you really want to use the URL I recommend you create a wrapper around s3.GetObjectInput that accepts the URL as an argument, parses it and then create the s3.GetObjectInput object.

    Also, I don't know if you could do this it depends on your use case, but if you are storing the URLs somewhere and that's why you want to use them, you can consider storing instead the presigned url with a long expiration time, and then when you want to fetch the object you can just use that URL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案