使用AWS SDK for PHP调用未定义的方法createPresignedUrl()
我无法使用AWS SDK for PHP创建预先签名的Url。我的密码是-使用AWS SDK for PHP调用未定义的方法createPresignedUrl(),php,amazon-s3,pre-signed-url,Php,Amazon S3,Pre Signed Url,我无法使用AWS SDK for PHP创建预先签名的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' =
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;
}
这给了我下一个错误-
致命错误:调用未定义的方法
Aws\Command::中的createPresignedUrl()
/Users/waverley_lv/waverley软件/workspace/fox.php.auto/sites/default/behat-tests/util/S3Utility.php
在线103
使用s3.0.0V3,我做了以下工作来实现这一点
$command = $s3->getCommand('GetObject', array(
'Bucket' => $this->customerBucket,
'Key' => $fileName,
'ContentType' => 'image/png',
'ResponseContentDisposition' => 'attachment; filename="'.$fileName.'"'
));
$signedUrl = $s3->createPresignedRequest($command, "+1 week");
使用s3.0.0V3,我做了以下工作来实现这一点
$command = $s3->getCommand('GetObject', array(
'Bucket' => $this->customerBucket,
'Key' => $fileName,
'ContentType' => 'image/png',
'ResponseContentDisposition' => 'attachment; filename="'.$fileName.'"'
));
$signedUrl = $s3->createPresignedRequest($command, "+1 week");
要在浏览器上强制下载任何文件,您可以使用:
$command=$s3->getCommand('GetObject',数组(
“Bucket”=>“bucketname”,
'键'=>'文件名',
'ResponseContentType'=>'application/octet stream',
“ResponseContentDisposition”=>“附件”
));
//从命令对象创建一个已签名的URL,该URL将持续
//距当前时间2分钟
$response=$s3->createPresignedRequest($command,'+2分钟');
$presignedUrl=(字符串)$response->getUri();
要强制下载浏览器上的任何文件,您可以使用:
$command=$s3->getCommand('GetObject',数组(
“Bucket”=>“bucketname”,
'键'=>'文件名',
'ResponseContentType'=>'application/octet stream',
“ResponseContentDisposition”=>“附件”
));
//从命令对象创建一个已签名的URL,该URL将持续
//距当前时间2分钟
$response=$s3->createPresignedRequest($command,'+2分钟');
$presignedUrl=(字符串)$response->getUri();
Dovar\u dump($s3)调用$s3=self::connect()后的代码>代码>。您可能无法取回所需的对象。您使用的AWS SDK版本是什么?我使用的是AWS SDK S3版本v2.1.39Dovar_dump($S3)调用$s3=self::connect()后的代码>代码>。您可能无法取回所需的对象。您使用的是AWS SDK的哪个版本?我使用的是AWS SDK S3版本v2.1.39