如何格式化 URL 以从 Amazon S3 获取文件?

发布于 2024-12-12 16:07:28 字数 885 浏览 0 评论 0原文

我在弄清楚如何从 Amazon S3 访问文件时遇到一些问题。假设文件所在的存储桶是 BUCKET_NAME,文件是 FILE_NAME 等。我尝试了以下两个 URL:

https://s3.amazonaws.com/BUCKET_NAME/FILE_NAME/
?Expires=EXPIRATION
&Signature=SIGNATURE
&SignatureVersion=2
&SignatureMethod=HmacSHA1
&AWSAccessKeyId=KEYID

但这给了我以下错误:

<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>

我也尝试过:

https://s3.amazonaws.com/BUCKET_NAME/
?Key=FILE_NAME
&Expires=EXPIRATION
&Signature=SIGNATURE
&SignatureVersion=2
&SignatureMethod=HmacSHA1
&AWSAccessKeyId=KEYID

但这会返回一个网页,其中包含给定存储桶中的所有文件(包括 FILE_NAME),而不是我想要的特定文件。我也尝试将 Action=GetObject 放入 URL 中,但这似乎没有改变任何东西。

找出哪种方法(如果有)是正确的方法以及我做错了什么会很有帮助。我已经研究亚马逊的文档有一段时间了,但我似乎无法整理出来。

I am having some trouble figuring out how to access a file from Amazon S3. Lets say that the bucket that the file lives in is BUCKET_NAME, the file is FILE_NAME, etc. I have tried the following two URLs:

https://s3.amazonaws.com/BUCKET_NAME/FILE_NAME/
?Expires=EXPIRATION
&Signature=SIGNATURE
&SignatureVersion=2
&SignatureMethod=HmacSHA1
&AWSAccessKeyId=KEYID

But this gives me the following error:

<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>

I have also tried:

https://s3.amazonaws.com/BUCKET_NAME/
?Key=FILE_NAME
&Expires=EXPIRATION
&Signature=SIGNATURE
&SignatureVersion=2
&SignatureMethod=HmacSHA1
&AWSAccessKeyId=KEYID

but this returns a webpage with a list of all of the files in the given bucket (including FILE_NAME), instead of the specific file I want. I have also tried throwing in Action=GetObject into the URL as well but that doesn't seem to change anything.

It would be helpful to find out which (if any) is the proper method and what I am doing wrong. I have been digging through Amazon's documentation for a while now but I can't seem to sort it out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

素染倾城色 2024-12-19 16:07:30

URL 格式

https://${bucketName}.s3.${region}.amazonaws.com/${key}

公共访问 URL 示例
https://store-files-in-s3.s3.ap-south-1.amazonaws.com/image-Fri+Mar+08+2024+17%3A45%3A07+GMT%2B0530+(印度+标准+Time).png

在上面的示例中键入:image-Fri Mar 08 2024 17:45:07 GMT+0530(印度标准时间).png

Format of the Url

https://${bucketName}.s3.${region}.amazonaws.com/${key}

Example of public access URL
https://store-files-in-s3.s3.ap-south-1.amazonaws.com/image-Fri+Mar+08+2024+17%3A45%3A07+GMT%2B0530+(India+Standard+Time).png

Key in above example: image-Fri Mar 08 2024 17:45:07 GMT+0530 (India Standard Time).png

牵强ㄟ 2024-12-19 16:07:29

也许不是 OP 所追求的,但对于那些搜索 URL 以简单地访问 S3 上的可读对象的人来说,更像是:

https://.amazonaws.com//< ;key>

其中 类似于 s3-ap-southeast-2

单击 S3 GUI 中的项目以获取您的存储桶的链接。

Perhaps not what the OP was after, but for those searching the URL to simply access a readable object on S3 is more like:

https://<region>.amazonaws.com/<bucket-name>/<key>

Where <region> is something like s3-ap-southeast-2.

Click on the item in the S3 GUI to get the link for your bucket.

初心 2024-12-19 16:07:29

正如 @stevebot 所说,执行以下操作:

https://.s3.amazonaws.com/

我想补充的一件重要的事情是,您要么使您的存储桶对象可公开访问,或者您可以将自定义策略添加到您的存储桶策略中。该自定义策略可能允许来自您的网络 IP 范围或不同凭据的流量。

As @stevebot said, do this:

https://<bucket-name>.s3.amazonaws.com/<key>

The one important thing I would like to add is that you either have to make your bucket objects all publicly accessible OR you can add a custom policy to your bucket policy. That custom policy could allow traffic from your network IP range or a different credential.

简单 2024-12-19 16:07:29

请注意,如果您位于不同的 AWS 分区,例如美国 GovCloud 或中国,那么您的 URL 模式将略有不同。

https://.s3-.amazonaws.com/ 适用于 GovCloud。

中国类似于 https://.s3-.amazonaws.com.cn/

Note that if you're in a different AWS partition, such as US GovCloud or China then you'll have a slightly different URL pattern.

https://<bucket-name>.s3-<region-name>.amazonaws.com/<key> works for GovCloud.

China is something like https://<bucket-name>.s3-<region-name>.amazonaws.com.cn/<key>.

但可醉心 2024-12-19 16:07:29

日期是 08.03.23,当前格式化 url 的方法是这样的:

https://<bucket>.s3.<region>.amazonaws.com/<key>

The date is 08.03.23 and the current way to format the url is this:

https://<bucket>.s3.<region>.amazonaws.com/<key>
天涯沦落人 2024-12-19 16:07:28

它实际上的表述更像是:

https://<bucket-name>.s3.amazonaws.com/<key>

请参阅此处

Its actually formulated more like:

https://<bucket-name>.s3.amazonaws.com/<key>

See here

清旖 2024-12-19 16:07:28

文档此处,我将使用法兰克福地区作为例子。

有 2 种不同的 URL 样式:

但此网址不起作用:

该消息是明确的:您尝试访问的存储桶必须使用指定的终端节点进行寻址。请将未来的所有请求发送到此端点。

我可能正在谈论另一个问题,因为我没有收到 NoSuchKey 错误,但我怀疑随着时间的推移,错误消息已变得更加清晰。

Documentation here, and I'll use the Frankfurt region as an example.

There are 2 different URL styles:

But this url does not work:

The message is explicit: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

I may be talking about another problem because I'm not getting NoSuchKey error but I suspect the error message has been made clearer over time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文