Laravel-medialibrary: Setting 'public' permission for files uploaded on S3

Created on 14 Jun 2016  Â·  6Comments  Â·  Source: spatie/laravel-medialibrary

Hi,

First of all let me tell you that your library is awesome. It save me a lot of time and avoid me to be writing boilerplate code. Nice!!

I would like to ask you, Is it possible to set the permission for an image (or whatever file) when it is uploaded to S3 via your library?. I mean, the picture I uploaded has a "private" permission by default, and I would like make it "public" readable. I was digging on the web and I found something like:

php $s3 = \Storage::disk('s3'); $filePath = '/support-tickets/' . $imageFileName; $s3->put($filePath, file_get_contents($image), 'public'); // Setting to 'public' the attribute.
The code above was took from https://chrisblackwell.me/upload-files-to-aws-s3-using-laravel/

However I want to do the same thing but using your library.

Any clue?

Thanks in advance

Most helpful comment

Add the custom header 'ACL' => 'public-read', to config/laravel-medialibrary.php.

Complete example:

'extra_headers' => [ 'CacheControl' => 'max-age=604800', 'ACL' => 'public-read', ]

All 6 comments

Thanks for the kind words on the package.

I don't know the exact setting by heart, but I'm pretty sure that in S3 you can specify somewhere (via a policy I believe) that all uploaded files should be public.

Oh I see, well I'm going to do more researching :p

Thanks so much!

2016-06-14 17:52 GMT-04:00 Freek Van der Herten [email protected]:

Thanks for the kind words on the package.

I don't know the exact setting by heart, but I'm pretty sure that in S3
you can specify somewhere (via a policy I believe) that all uploaded files
should be public.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/spatie/laravel-medialibrary/issues/241#issuecomment-226027435,
or mute the thread
https://github.com/notifications/unsubscribe/AJzLMifMG6yG7KkMUBznVKZaYnj0l0Viks5qLyKUgaJpZM4I1hfW
.

Add the custom header 'ACL' => 'public-read', to config/laravel-medialibrary.php.

Complete example:

'extra_headers' => [ 'CacheControl' => 'max-age=604800', 'ACL' => 'public-read', ]

@freekmurze a policy in this case is a "global thing".

@palpalani This makes all files public after this config change.

If you want to set the permission for every upload individually you can do this like so even your bucket is set to private:

    $model->addMedia($file)
        ->addCustomHeaders([
            'ACL' => 'public-read'
        ])
        ->toMediaCollection($type);

@divdax thanks for your answer, but do you know any way to apply public read to the conversions? thanks!

@omacesc no it's a bug i already reported: #868

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kickthemooon picture kickthemooon  Â·  4Comments

Krato picture Krato  Â·  4Comments

Nks picture Nks  Â·  3Comments

jam1e picture jam1e  Â·  3Comments

amrnn90 picture amrnn90  Â·  3Comments