Laravel5: Securing Files on AWS S3

Spent the whole afternoon searching for answers to secure files on AWS S3. Here is how I solve it:

Upload the files to S3 as “private” files. So the public users won’t have access even knowing the file url.

Then use Laravel routing to retrieve the file. And at the same time, adding auth middleware to the route.

Firstly, upload the file to S3. There are plenty of examples. Below is the one I use for summernote.

Then for routes/web.php, add a new route to retrieve the file.

You may need to restart the php-fpm to make it effective.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.