Skip to content

Instantly share code, notes, and snippets.

@jhesyong
Created October 14, 2015 07:32
Show Gist options
  • Save jhesyong/e650a0e7f1f9d580d6f1 to your computer and use it in GitHub Desktop.
Save jhesyong/e650a0e7f1f9d580d6f1 to your computer and use it in GitHub Desktop.
Get presigned url of private file
function getFilePathAttribute($value)
{
$disk = Storage::disk('s3');
if ($disk->exists($value)) {
$command = $disk->getDriver()->getAdapter()->getClient()->getCommand('GetObject', [
'Bucket' => Config::get('filesystems.disks.s3.bucket'),
'Key' => $value,
]);
$request = $disk->getDriver()->getAdapter()->getClient()->createPresignedRequest($command, '+5 minutes');
return (string) $request->getUri();
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment