Created
January 15, 2021 09:31
-
-
Save loughlincodes/4da1718914c1299ec733b89c157223e5 to your computer and use it in GitHub Desktop.
Private function to get an S3 asset url using a presigned request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the url of an S3 file | |
* @param [string] $key [naem of the file object on S3 e.g. logs/thisismylog.txt] | |
* @return [string] url to the file | |
*/ | |
private function getFileUrl($key) { | |
$s3 = Storage::disk('s3'); | |
$client = $s3->getDriver()->getAdapter()->getClient(); | |
$bucket = config("filesystems.disks.s3.bucket"); | |
$command = $client->getCommand('GetObject', [ | |
'Bucket' => $bucket, | |
'Key' => $key | |
]); | |
$request = $client->createPresignedRequest($command, '+20 minutes'); | |
return (string) $request->getUri(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment