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

时间:2015-04-15 13:52:14

标签: php amazon-web-services amazon-s3

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

require '.vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

// 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
是什么意思? 感谢。

2 个答案:

答案 0 :(得分:0)

尝试创建实例如何:

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

使用您所在的地区

答案 1 :(得分:0)

问题是对公共IP的限制。 但是,脚本干净正确。 感谢。

相关问题