我需要在eu-central-1中为一个存储桶过期下载链接。
使用SDK-PHP中的$s3->getObjectUrl($bucket, $filename, '+5 minutes');
,我只会在没有查询字符串的情况下获取http://.../file.txt这样的非带状网址。
完整代码:
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
我不知道为什么?
答案 0 :(得分:1)
AHHHH,
getObjectUrl
不再有第三个参数。
这个作品:
$cmd = $client->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => 'test1G.dat'
]);
$request = $client->createPresignedRequest($cmd, '+20 minutes');
$presignedUrl = (string) $request->getUri();