Come generare un PreSignedUrl in Amazon S3
Cosa ho imparato oggi: come generare un PreSignedUrl in Amazon S3 che forza il download di un file.
Fonti:
- http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html
- http://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/s3-presigned-url.html
$client = S3Client::factory([
'credentials' => [
'key' => config('filesystems.disks.s3.key'),
'secret' => config('filesystems.disks.s3.secret'),
],
'version' => '2006-03-01',
'region' => config('filesystems.disks.s3.region'),
]);
$cmd = $client->getCommand('GetObject', [
'Bucket' => config('filesystems.disks.s3.bucket'),
'Key' => 'folder/file.pdf',
'ResponseContentDisposition' => 'attachment; filename="FileName.pdf"',
]);
$request = $client->createPresignedRequest($cmd, '+10 minutes');
$url = (string) $request->getUri();
print($url);




