PHP的S3Client获得有效的Uri访问被拒绝的XML

时间:2018-08-15 18:51:22

标签: php amazon-s3 knox-amazon-s3-client minio aws-php-sdk

我从this link安装了S3Client软件包。

我的文件成功上传到存储桶中,但是当我在浏览器中复制有效的Uri时,出现如下图所示的AccessDenied XML错误:

enter image description here

<?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并下载文件?

0 个答案:

没有答案