我可以使用aws-sdk从我的电脑上传文件到aws s3吗?

时间:2018-06-05 02:49:30

标签: amazon-s3

我尝试从本地上传文件到aws s3使用aws-sdk但是我收到错误:访问被拒绝。我附上了AmazonS3FullAccess政策。我正在使用终端来运行代码。 php upload.php

我的代码:

require 'aws/aws-autoloader.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

// Set Amazon s3 credentials
$client = S3Client::factory(
  array(
    'credentials' => array(
        'key'    => "mykey",
        'secret' => "myscret",
    ),   
    'region' => "ap-southeast-1",
    'version' => "latest"
  )
);

try {
  $client->putObject(array(
    'Bucket'=>'mybucket',
    'Key' => 'text.txt',
    'Body' => 'Hello, world!',
    'ACL'    => 'public-read',
    's3'=>'PutObject'
    // 'StorageClass' => 'REDUCED_REDUNDANCY'
  ));

} catch (S3Exception $e) {
  // Catch an S3 specific exception.
  echo $e->getMessage();
}

0 个答案:

没有答案