为什么在使用 aws-sdk-php 上传文件时拒绝访问



我不知何故迷路了,我是 aws 新手,所以我在 myproject 中安装了 aws-sdk-php,我正在尝试测试上传;这是脚本的代码段:

require '.vendor/autoload.php';
use AwsS3S3Client;
use AwsS3ExceptionS3Exception;
// Instantiate an S3 client
$s3 = S3Client::factory(array(
    'credentials' => array(
        'key'    => 'key ... ',
        'secret' => 'secret key ... ',
    )
)); 
$file_name = $_FILES['file']['tmp_name'];
try {
    $s3->putObject(array(
        'Bucket' => 'bucket_name',
        'Key'    => $_FILES['file']['name'],
        'Body'   => fopen($file_name, 'r'),
        'ACL'    => 'public-read',
    ));
    echo " upload succed !!";
} catch (S3Exception $e) {
    echo "There was an error uploading the file.n";
    echo $e->getMessage() . "n";
}

此代码在本地测试中工作正常,但是当尝试在 S3 中文件夹中的项目中测试相同的脚本时;我收到此错误:

There was an error uploading the file. Access Denied

请问有什么想法吗?谢谢。

尝试如何创建实例:

$s3 = S3Client::factory(array(
        'key' => 'key',
        'secret' => 'secret',
        'region' => 'eu-west-1'
    ));

使用您所在的地区

问题是对公共IP的限制。然而,脚本是干净和正确的。谢谢。

最新更新