我正在尝试设置URL的到期但由于某种原因它没有按预期工作,并且即使在过期后网址仍然存在
php code
$object = 'uploads/496c53309bac48e4d65f55d9d66c0ac0.txt';
$url = $s3->getObjectUrl($config['s3']['bucket'], $object, '10 seconds');
html代码
<body>
<a href="<?php echo $url; ?>">Download Link</a>
</body>
我正在使用AWS SDK 2.7.5
答案 0 :(得分:1)
&#39; getObjectUrl&#39;只会创建一个常规的S3网址,它只需要两个参数。
要使用预先签名的网址,根据SDK documentation
需要多一点// Get a command object from the client and pass in any options
// available in the GetObject command (e.g. ResponseContentDisposition)
$command = $client->getCommand('GetObject', array(
'Bucket' => $bucket,
'Key' => 'data.txt',
'ResponseContentDisposition' => 'attachment; filename="data.txt"'
));
// Create a signed URL from the command object that will last for
// 10 minutes from the current time
$signedUrl = $command->createPresignedUrl('+10 minutes');
echo file_get_contents($signedUrl);
// > Hello!