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 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services