使用Filesystem Laravel 5.2从Amazon S3获取文件的签名URL [英] Get file's signed URL from amazon s3 using Filesystem Laravel 5.2
问题描述
我正在寻找一个很好的解决方案,以从Amazon s3获取签名的URL.
I'm looking for a good solution to get the signed url from amazon s3.
我有一个可以使用的版本,但是没有使用laravel:
I have a version working with it, but not using laravel:
private function getUrl ()
{
$distribution = $_SERVER["AWS_CDN_URL"];
$cf = Amazon::getCFClient();
$url = $cf->getSignedUrl(array(
'url' => $distribution . self::AWS_PATH.rawurlencode($this->fileName),
'expires' => time() + (session_cache_expire() * 60)));
return $url;
}
我不认为这是使用laravel的最佳方法,因为它具有整个文件系统都可以工作...
I don't know if this is the best way to do with laravel, considering it has a entire file system to work...
但是如果没有其他方法,我如何获得客户?调试我已经在Filesystem对象中找到了它的一个实例,但是它是受保护的...
But if don't have another way, how do I get the client? Debugging I've found an instance of it inside the Filesystem object, but it is protected...
推荐答案
在Laravel中,
$s3 = \Storage::disk('s3');
$client = $s3->getDriver()->getAdapter()->getClient();
$expiry = "+10 minutes";
$command = $client->getCommand('GetObject', [
'Bucket' => \Config::get('filesystems.disks.s3.bucket'),
'Key' => "file/in/s3/bucket"
]);
$request = $client->createPresignedRequest($command, $expiry);
return (string) $request->getUri();
确保您也拥有适用于flysystem的AWS for Composer软件包(版本会有所不同):
Make sure you have the AWS for flysystem composer package too (version will vary):
"league/flysystem-aws-s3-v3": "1.0.9"
这篇关于使用Filesystem Laravel 5.2从Amazon S3获取文件的签名URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!