Skip to content

S3 Demo

JP edited this page Oct 31, 2017 · 3 revisions

About S3

From the product page:

Amazon S3 stores data as objects within resources called "buckets". You can store as many objects as you want within a bucket, and write, read, and delete objects in your bucket. Objects can be up to 5 terabytes in size. You can control access to the bucket (who can create, delete, and retrieve objects in the bucket for example), view access logs for the bucket and its objects, and choose the AWS region where a bucket is stored to optimize for latency, minimize costs, or address regulatory requirements.

Steps

  1. Ensure that you have populated these directives on the .env file:

    • AWS_S3_BUCKET_NAME
    • AWS_S3_REGION
  2. Run php artisan config:clear.

  3. Send a POST request to the aws/s3/upload URI:

    aws-s3-upload

  4. A successful upload should give you an ObjectURL that you can check for yourself:

    aws-s3-upload-success

    (The default content disposition for S3 would be for files to download automatically and not display on the browser.)

  5. Confirm that the file actually now exists on your S3 file system:

    aws-s3-upload-success-aws-dashboard

Questions

How do I allow/restrict other websites from displaying my S3-stored files (e.g. images).

You can configure Cross-Origin Resource Sharing (CORS) on individual buckets. This effectively prevents un-whitelisted hostnames from hotlinking and embedding your bucket resources. This way, only those who have been whitelisted can:

  • Use your CSS stylesheets/JavaScripts
  • Display your images

How do I want get more granular control over my bucket?

There are numerous guides about establishing bucket policies. Have a read at this official article from AWS.

Bucket policies can help you:

  • Restrict access to specific IP addresses
  • Restrict access to specific HTTP referrer

... and a lot more.

Clone this wiki locally