amazon-s3 - 我可以使用 aws-sdk 将文件从我的计算机上传到 aws s3 吗?
问题描述
我尝试使用 aws-sdk 将文件从本地上传到 aws s3,但出现错误:访问被拒绝。我附加了 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();
}
解决方案
推荐阅读
- r - 如何将多行标题/列名称添加到 R 中的数据框
- angular - 如何使用角和角材料将步进器从一步移动到第二步
- javascript - 当输入日期字段中有值时如何使按钮启用
- identityserver4 - 身份服务器多租户,每个租户数据库的身份表
- java - 如何计算两个 timeStamp (不同天数)之间的分钟差?
- javascript - 如何仅触发一个事件“更改”或“点击”
- amazon-web-services - 我们可以从备份恢复到同一个 dynamodb 表吗
- python - TensorFlow 2 中许多伪数据实现的优化函数
- c - 插入多个(2次)数字签名,我发现pdf中有3个信息字典
- python - boost::odeint 和 scipy.integrate 中微分方程的解完全不同