从S3存储桶中读取文件。

huangapple go评论108阅读模式
英文:

read file from s3 bucket

问题

我正在尝试使用Golang从S3存储桶获取文件。我的请求中有一个特殊之处,即我需要从S3的根目录获取文件。在我的情况下,我有一个名为"buckets"的文件夹,它是S3的根目录,在其中我有其他文件夹和文件。我需要从"buckets"文件夹获取文件。这意味着我没有一个名为"bucket"的文件夹,因为我只能访问根目录。
我尝试的代码如下:

numBytes, err := downloader.Download(file, &s3.GetObjectInput{
  Bucket: aws.String("/"),
  Key:   aws.String("some_image.jpeg"),
})

问题是我收到了一个说对象不存在的错误。是否可以从S3的根目录读取文件?我需要在bucket中写什么?key的写法正确吗?

非常感谢您的帮助!

英文:

I'm trying to get a file from s3 bucket with golang. What's special in my request is that I need to get a file from the root of the s3. i.e, in my situation, i have a buckets folder which is the root for the s3, inside that i have folders and files. I need to get the files from the buckets folder. it means that i don't have a bucket folder because i access only to the root.
the code im trying is:

numBytes, err := downloader.Download(file, &s3.GetObjectInput{
  Bucket: aws.String("/"),
  Key:   aws.String("some_image.jpeg"),
})

The problem is I got an error that says the object does not exist.
Is it possible to read files from the root of s3? What do I need to write in the bucket? the key is written okay?

Many thanks for helping!

答案1

得分: 1

所有的文件都存储在S3桶中。你不能将文件存储在S3的根目录中。

每个桶都有自己独立的命名空间。你可以在你的Amazon账户中拥有多个桶,每个文件必须属于其中一个桶。

你可以使用AWS网页界面、命令行工具或API来创建一个桶。(或者使用第三方软件如Cyberduck)。

你可以在这里了解更多关于S3桶的信息:https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingBucket.html

英文:

All files in S3 are stored inside buckets. You're not able to store a file in the root of s3.

Each bucket is its own distinct namespace. You can have multiple buckets in your Amazon account, and each file must belong to one of those buckets.

You can either create a bucket using the AWS web interface, command line tools or API. (Or 3rd party software like Cyberduck).

You can read more about buckets in S3 here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingBucket.html

huangapple
  • 本文由 发表于 2022年1月2日 02:43:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/70551056.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定