【发布时间】:2018-02-26 14:52:24
【问题描述】:
我知道 S3 中没有文件夹的概念,它使用平面文件结构。不过,为了简单起见,我将使用术语“文件夹”。
前提条件:
- 一个名为 foo 的 s3 存储桶
- 文件夹 foo 已使用 AWS 管理控制台公开
- 阿帕奇
- PHP 5
- 标准 AWS 开发工具包
问题:
可以使用 AWS PHP 开发工具包上传文件夹。但是,该文件夹只能由上传该文件夹的用户访问,而不是像我希望的那样公开可读。
程序:
$sharedConfig = [
'region' => 'us-east-1',
'version' => 'latest',
'visibility' => 'public',
'credentials' => [
'key' => 'xxxxxx',
'secret' => 'xxxxxx',
],
];
// Create an SDK class used to share configuration across clients.
$sdk = new Aws\Sdk($sharedConfig);
// Create an Amazon S3 client using the shared configuration data.
$client = $sdk->createS3();
$client->uploadDirectory("foo", "bucket", "foo", array(
'params' => array('ACL' => 'public-read'),
'concurrency' => 20,
'debug' => true
));
成功标准:
我可以使用“静态”链接访问上传文件夹中的文件。外汇:
https://s3.amazonaws.com/bucket/foo/001.jpg
【问题讨论】:
标签: php amazon-web-services amazon-s3