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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog