0
我無法使用適用於PHP的AWS開發工具包創建Presigned Url。我的代碼 -使用適用於PHP的AWS開發工具包調用未定義的方法createPresignedUrl()
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;
}
它給了我未來無差錯
Fatal error: Call to undefined method Aws\Command::createPresignedUrl() in /Users/waverley_lv/WaverleySoftware/workspace/fox.php.auto/sites/default/behat-tests/util/S3Utility.php on line 103
在你調用'$ s3 = self :: connect();'''''''''''''之後'執行'var_dump($ s3)你可能沒有找回你期待的對象。 – nickb
您使用的是什麼版本的AWS SDK? –
我正在使用AWS SDK S3 - 發佈v2.1.39 –