Php 使用PutObject将blob上载到S3存储桶不会';t工作:签名不匹配。为什么?
尝试将映像作为blob上载到S3存储桶失败,错误如下:Php 使用PutObject将blob上载到S3存储桶不会';t工作:签名不匹配。为什么?,php,amazon-web-services,amazon-s3,aws-sdk,Php,Amazon Web Services,Amazon S3,Aws Sdk,尝试将映像作为blob上载到S3存储桶失败,错误如下: <Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calcul (truncated...) SignatureDoesNotMatch (client): The request signature we calculated does not match the signature you
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calcul (truncated...)
SignatureDoesNotMatch (client): The request signature we calculated does not match the signature you provided. Check your key and signing method. - <?xml version="1.0" encoding="UTF-8"?>
凭据是从/.aws/credentials
文件中提取的,我知道它们是有效的,因为从文件中提取的putObject
非常有效。这只是无法上传的blob
在本例中,S3类具有以下感兴趣的部分:
class S3_model extends CI_Model {
private $s3Client;
private $s3Config = [
'version' => '2006-03-01', // See `version` parameter documentation here: http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html
'region' => 'eu-central-1'
];
private $bucket = 'tprdev';
public function __construct ()
{
parent::__construct();
$this->load->model('log_model');
$this->s3Client = new Aws\S3\S3Client($this->s3Config);
}
public function putObjectFromBlob ($key, $blob)
{
try {
$params = [
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => $blob
];
$this->s3Client->putObject($params);
$this->s3Client->waitUntil('ObjectExists', $params);
} catch (Exception $e) {
$this->log_model->log("{$e->getMessage()}\n{$e->getTraceAsString()}");
return false;
}
return true;
}
}
事实证明,我使用的这个新版本的SDK对带有前导斜杠的对象键非常挑剔。我已经删除了前导斜杠,Blob现在上传。错误(imho)实际上是旧SDK过于宽容。从技术上讲,对象键中的前导斜杠一直是错误的,
/
表示存储桶的根,但实际上不是对象键的第一个字符(没有名为/
)的对象),但较旧的代码将其视为可选字符,从而容忍了它。我不知道这是偶然的还是有意的(“有益的”)设计+1.整理你自己的问题。