Laravel-medialibrary: S3 permissions

Created on 28 Oct 2017  路  3Comments  路  Source: spatie/laravel-medialibrary

Hello everyone. After upload file to S3 all files is private by default.
So when i use getUrl() and go to this url i get this from amazon:
Image of error

So my question is, how can i configure when uploading to upload file as public ?
This is permissions of my bucket:
Bucket permissions.

If i will setup in bucket policies that GetObject is by default for all, then this will make no sense:
$temporaryS3Url = $mediaItems[0]->getTemporaryUrl(Carbon::now()->addMinutes(5));

P.S. if i manually make file public - then it's shown.

Most helpful comment

you either add 'ACL' => 'public-read' to your config file, or Adjust the Bucket Policy it self having from s3 console manager.
Something similar to this:

{
    "Version": "2012-10-17",
    "Id": "PolicyId",
    "Statement": [
        {
            "Sid": "SomeValidId",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "s3:GetObject",
                "s3:GetObjectAcl"
            ],
            "Resource": "arn:aws:s3:::bucketName/*"
        }
    ]
}

All 3 comments

I have exactly the same problem

I now see in fact that this is already solved earlier:
https://github.com/spatie/laravel-medialibrary/issues/241

you either add 'ACL' => 'public-read' to your config file, or Adjust the Bucket Policy it self having from s3 console manager.
Something similar to this:

{
    "Version": "2012-10-17",
    "Id": "PolicyId",
    "Statement": [
        {
            "Sid": "SomeValidId",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "s3:GetObject",
                "s3:GetObjectAcl"
            ],
            "Resource": "arn:aws:s3:::bucketName/*"
        }
    ]
}
Was this page helpful?
0 / 5 - 0 ratings