Ous*_*ane 7 acl amazon-s3 symfony gaufrette
我正在使用KnpGaufretteBundle在Amazon S3上存储图片,我可以使用以下代码轻松创建文件:
public function s3CreatFileAction(Request $request) {
$filesystem = $this->get('knp_gaufrette.filesystem_map')->get('profile_photos');
$filesystem->write('test.txt', 'hello world');
[...]
}
Run Code Online (Sandbox Code Playgroud)
问题是我无法访问该文件...
$filesystem = $this->get('knp_gaufrette.filesystem_map')->get('profile_photos');
$file = $filesystem->get('test.txt');
Run Code Online (Sandbox Code Playgroud)
我收到以下消息:
找不到文件"test.txt".
我认为这是因为"test.txt"文件是使用"私有"acl创建的(当我将其公开时,我可以访问它的S3控制台).
所以我的问题是如何在创建对象时定义公共acl?
Ous*_*ane 18
好吧,看来KnpGaufretteBundle的文档看起来像丛林☹......
这是我的解决方案:
#app/config/config.yml
services:
acme.aws_s3.client:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
-
credentials:
key: %amazon_s3.key%
secret: %amazon_s3.secret%
region: %amazon_s3.region%
version: %amazon_s3.version%
# knp_gaufrette
knp_gaufrette:
adapters:
profile_photos:
aws_s3:
service_id: 'acme.aws_s3.client'
bucket_name: 'myBucket'
options:
directory: 'myDirectory'
acl: 'public-read'
Run Code Online (Sandbox Code Playgroud)
在我的第一次试验中,这段代码无效,因为我的AwsS3用户没有正确的权限!因此,请确保您的用户的策略允许访问存储桶!
| 归档时间: |
|
| 查看次数: |
1881 次 |
| 最近记录: |