创建用于从S3存储桶获取文件的签名URL时出错?

时间:2019-12-11 18:04:23

标签: php amazon-web-services codeigniter amazon-s3

enter image description here

在对sr bucket使用createPresignedUrl()函数时遇到错误。

$s3Client  = new S3($awsAccessKey, $awsSecretKey);


$command = $s3Client->getObject($bucket, $filename);
$request = $s3Client->createPresignedUrl($command, '+1 minutes');

        // Get the actual presigned-url
$presignedUrl = (string)$request->getUri();

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作

include_once('../aws/aws-autoloader.php');
        $s3Client = new Aws\S3\S3Client([
            'version' => '2006-03-01', // Change as per your version
            'region' => 'ap-south-1', // Change as per your region
            'credentials' => [
                'key' => ACCESS_KEY_ID, // Your access key
                'secret' => SECRET_ACCESS_KEY, // Your secret key
            ],
        ]);

        $cmd = $s3Client->getCommand('GetObject', [
            'Bucket' => BUCKET_NAME,
            'Key' => $file
        ]);

        $request = $s3Client->createPresignedRequest($cmd, '+' . (60 * 24 * 7) . ' minutes');
       $presignedUrl = (string) $request->getUri(); // here you got URL