Create Sing S3 download link with signature algorithm version 4

I need expiring download links for the bucket in eu-central-1.

With $s3->getObjectUrl($bucket, $filename, '+5 minutes');

from SDK-PHP I only get typed urls like http: //.../file.txt without being prompted.

Code:

require 'vendor/autoload.php';
use Aws\S3\S3Client;

$client = S3Client::factory([
    'version' => 'latest',
    'region'  => 'eu-central-1',
    'signature'    => 'v4',
    'credentials' => [
        'key'    => 'xxxxx',
        'secret' => 'xxxxx'
    ]
]);

$plainUrl = $client->getObjectUrl('mybucket', 'data.txt');
// > https://my-bucket.s3.amazonaws.com/data.txt

$signedUrl = $client->getObjectUrl('mybucket', 'data.txt', '+10 minutes');
// > https://my-bucket.s3.amazonaws.com/data.txt

      

I do not know why?

+3


source to share


1 answer


Aaaaa, getObjectUrl

no longer has a third parameter. It works:



$cmd = $client->getCommand('GetObject', [
    'Bucket' => $bucket,
    'Key'    => 'test1G.dat'
]);

$request = $client->createPresignedRequest($cmd, '+20 minutes');
$presignedUrl = (string) $request->getUri();

      

+1


source







All Articles