Архив рубрики: Laravel

Pre-Signed URL for Amazon S3 Object

It’s so easy enough than I thought before!

At first let’s upload file to chosen bucket. Below is a live example from my Laravel 5 project:

I’ve set ACL to ‘authenticated-read’ (it was ‘public-read’ before) because the aim of pre-signed URL is to restrict access and give it only to authorized users (who have valid link).

Then if we want to get actual download URL let’s get our S3 client:

Then get appropriate command:

Get request to execute this command:

And finally get the pre-signed Url to download private resource!

I’m using a kind of download controller that acts as proxy of user request to download a private file so the result of its work is a redirect to actual resource URL:

Eloquent model default values

Tryin’ to find a way to set default model values in Eloquent model (speaking about Laravel ORM) I was surprised that there’s no any mention about it in official docs. So thanks to fellas from StackOverflow such a workaround was found:

This example shows you how to set default value to ‘foo’ model property (model field, attribute, etc) if you’re creating a new FooModel record. Читать далее