【问题标题】:S3 List Objects request on a bucket to get additional keys (> 1000)存储桶上的 S3 List Objects 请求以获取其他密钥(> 1000)
【发布时间】:2011-07-20 00:08:07
【问题描述】:

默认情况下,S3 List Objects (Get Bucket) 请求会返回 1000 个键。根据 S3 文档,如果我想列出更多对象,那么我必须将标记查询字符串与我的请求一起传递,并将标记的值设置为上一个对象列表中的最后一个键。

由于某种原因,这对我不起作用......我似乎遗漏了一些明显的东西,我正在尝试找出什么。

这就是 REST 请求的样子:

GET ?marker=LAST-KEY HTTP/1.1
Host: quotes.s3.amazonaws.com
Date: Wed, 01 Mar  2009 12:00:00 GMT
Authorization: AWS ACCESS_KEY_ID:SIGNATURE

我的 PHP 代码如下所示:

...
// this is where I'm getting the value of the last key
$marker=$arrObjects["Contents"][999]["Key"];
...
//this is where I'm signing my request
$canonicalizedResources = "/".$bucketName."/".(($marker=="")?"":"?marker=".rawurlencode($marker));
// $contentMD5 and $contentType are both empty strings ""
$stringToSign = utf8_encode("GET"."\n".$contentMD5."\n".$contentType."\n".$timestamp."\n".$canonicalizedAmzHeaders.$canonicalizedResources);
$signature = base64_encode(hash_hmac("sha1",$stringToSign,$customerSecretKey,true));
...

如果我在存储桶中列出数量小于 1000 的对象,此代码可以完美运行。但每当我将标记传递给请求时,我都会收到“签名不匹配”错误。

有人知道我哪里出错了吗?

【问题讨论】:

  • 为什么,哦,为什么不直接使用SDK
  • 因为 SDK 不支持 devpay s3 存储桶

标签: php amazon-s3


【解决方案1】:

要跟进@Skyler 的评论,使用 SDK,您的代码可能如下所示(减去授权位):

// Instantiate the class
$s3 = new AmazonS3();

$response = $s3->list_objects('my-bucket');

更多内容请关注AWS docs

【讨论】:

  • 我要看看我是否可以让 sdk 与 devpay 存储桶一起工作
  • @mythical_man_moth - 啊,我想这是不使用它的好理由。 :( - 我发现 this 论坛指向 github repository 可能会帮助您实现这一点。
猜你喜欢
  • 2017-05-23
  • 2014-03-10
  • 1970-01-01
  • 2021-01-20
  • 1970-01-01
  • 1970-01-01
  • 2021-10-18
  • 2018-01-10
  • 2016-08-05
相关资源
最近更新 更多