我无法使用适用于 PHP 的 AWS 开发工具包创建预签名 URL。我的代码是 -
function connect()
{
// Instantiate the S3 class and point it at the desired host
date_default_timezone_set('GMT');
return S3Client::factory(array(
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => [
'key' => $key,
'secret' => $secret
]
));
function getSignedS3URLForObject($fileName)
{
// GET CURRENT DATE
$milliseconds = round(microtime(true) * 1000);
$expiration = $milliseconds + (1000 * 60 * 60 * 24 * 30 * 2);
$s3 = self::connect();
$command = $s3->getCommand('GetObject', array(
'Bucket' => self::$customerBucket,
'Key' => $fileName,
'ContentType' => 'image/jpeg',
'Body' => '',
'ContentMD5' => false
));
$signedUrl = $command->createPresignedUrl($expiration);
echo urldecode($signedUrl);
return $signedUrl;
}
它给了我下一个错误-
致命错误:在第 103 行的 /Users/waverley_lv/WaverleySoftware/workspace/fox.php.auto/sites/default/behat-tests/util/S3Utility.php 中调用未定义的方法 Aws\Command::createPresignedUrl()