thib92 / flysystem-public-url-plugin

Flysystem plugin to get the public URL of a file
3 stars 0 forks source link

Get signed URL for AWS S3 #8

Open baudev opened 4 years ago

baudev commented 4 years ago

Currently, the adapter for AWS s3 v3 only allows you to retrieve the URL of an object:

https://github.com/thib92/flysystem-public-url-plugin/blob/f5903ea19a91bc1e34c618de869311191899234c/src/Adapter/AwsS3UrlAdapter.php#L26

This can be annoying if you have a private bucket and you want a public url that does not require authentication (convenient for browsers).


The solution is therefore to generate a signed url (see here):

//Creating a presigned URL
$cmd = $s3Client->getCommand('GetObject', [
    'Bucket' => 'my-bucket',
    'Key' => 'testKey'
]);

$request = $s3Client->createPresignedRequest($cmd, '+20 minutes');

// Get the actual presigned-url
$presignedUrl = (string)$request->getUri();

I'll try to do a PR if I have time :wink:

thib92 commented 4 years ago

This is needed yes. However, I think it needs to add some features to the global plugin: the end user should be able to pass parameters to the S3 command. So something like this: $filesystem->getPublicUrl($filename, $params);.

So we need to be able to pass optional parameters to the getPublicUrl method.

baudev commented 4 years ago

It seems to be a good solution indeed :+1: