Iho*_*kit 0 php amazon-s3 pre-signed-url
我无法使用适用于 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;
}
Run Code Online (Sandbox Code Playgroud)
它给了我下一个错误-
致命错误:在第 103 行 /Users/waverley_lv/WaverleySoftware/workspace/fox.php.auto/sites/default/behat-tests/util/S3Utility.php 中调用未定义方法 Aws\Command::createPresignedUrl()
小智 5
要强制下载浏览器上的任何文件,您可以使用:
$command = $s3->getCommand('GetObject', array(
'Bucket' => 'bucketname',
'Key' => 'filename',
'ResponseContentType' => 'application/octet-stream',
'ResponseContentDisposition' => 'attachment'
));
// Create a signed URL from the command object that will last for
// 2 minutes from the current time
$response = $s3->createPresignedRequest($command, '+2 minutes');
$presignedUrl = (string)$response->getUri();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3070 次 |
| 最近记录: |