使用PutObject将blob上载到S3存储桶不起作用:SignatureDoesNotMatch。为什么?

问题描述 投票:1回答:1

尝试将映像作为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 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;
}
}
php amazon-web-services amazon-s3 aws-sdk
1个回答
1
投票

事实证明,我使用的这个新版本的SDK对于带有前导斜杠的对象键很挑剔。我删除了前导斜杠,现在上传了blob。

© www.soinside.com 2019 - 2024. All rights reserved.