aws s3 php sdk 2 SignatureDoesNotMatch Error


aws s3 php sdk 2 SignatureDoesNotMatch Error

我在ap-southeast-1区域创建了一个bucket,ACL设置为private read。我能够使用AWS PHP SDK 2 S3Client类成功地将文件上传到bucket中的文件夹中。但是,我还需要在应用程序中显示这些文件的链接。因此,当用户单击按钮时,我会向服务器文件发送一个AJAX请求,并获得签名的URL,该URL通过json字符串返回给用户。但是,url总是返回一个带有错误SignatureDoesNotMatch的XML。

获取以下签名URL的代码:

 //create the AWS reference string
    $client = S3Client::factory(
                             array(
                                'key'    => T_AWS_KEY,
                                'secret' => T_AWS_SECRET,
                                'region' => T_BASE_REGION
                                )
                             );
    //method 1  - using Command Object
    $command = $client->getCommand('GetObject', array(
        'Bucket' => T_BASE_BUCKET . "/" . $firmId . "/invoices" ,
        'Key' => $arr['file_reference_url'] ,
        'ResponseContentDisposition' => 'attachment;filename=' . arr['file_reference_url']
    ));
    $signedUrl = $command->createPresignedUrl('+10 minutes');
    echo $signedUrl . "'n'n";
    //method 2 - using getObjectUrl
    echo $client->getObjectUrl(T_BASE_BUCKET . "/" . $firmId .  "/invoices", $arr['file_reference_url'], "+10 minutes");

感谢您的帮助。

您可能对bucket是什么感到困惑。Buckets未嵌套。T_BASE_BUCKET的值很可能是您的BUCKET,而其他部分则是对象键的一部分。试试看:

$objectKey = $firmId . '/invoices/' . $arr['file_reference_url'];
echo $client->getObjectUrl(T_BASE_BUCKET, $objectKey, '+10 minutes');
相关文章:
  • 没有找到相关文章