默认情况下,S3 List Objects
(获取存储桶)请求返回 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 的桶中列出对象,此代码将完美运行。但是每当我将标记传递给请求时,我都会收到“签名不匹配”错误。
有人知道我错在哪里吗?
最佳答案
要跟进@Skyler 的评论,使用 SDK,您的代码可能如下所示(减去授权位):
// Instantiate the class
$s3 = new AmazonS3();
$response = $s3->list_objects('my-bucket');
更多内容在 AWS docs .
关于php - 存储桶上的 S3 List Objects 请求以获取额外的 key (> 1000),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383545/