我从this link安装了S3Client软件包。
我的文件成功上传到存储桶中,但是当我在浏览器中复制有效的Uri时,出现如下图所示的AccessDenied XML错误:
<?php
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'endpoint' => 'http://127.0.0.1:9000',
'use_path_style_endpoint' => true,
'credentials' => [
'key' => 'mykey',
'secret' => 'mysecret',
],
]);
try {
$key = 'samplekey';
$bucketName = 'bucketName';
$filePath = 'filePath';
$this->s3->putObject([
'Bucket' => $bucketName,
'Key' => $key,
'Body' => fopen($filePath, 'r'),
'ACL' => 'public-read',
]);
$fileUrl = $cmd = $this->s3->getCommand('GetObject', [
'Bucket' => $bucketName,
'Key' => $key
]);
$request = $this->s3->createPresignedRequest($cmd, '+1 minutes');
//Get the pre-signed URL
$signedUrl = (string)$request->getUri();
return $signedUrl;
} catch (S3Exception $e) {
throw new UploadFileException();
}
?>
我如何获取文件URL并下载文件?