This is an example of how to do secure and direct to s3 uploads from a rails app. It uses the jQuery-File-Upload plugin and rails 5.2.3
If you want a step by step guide on how this all works check it out here.
- Clone the project
bundle
- Setup a
.env
file based on.env.example
in the project root:cp .env.example .env
This includes your aws keys and bucket information. - Setup CORS on your s3 bucket (see below)
rails s
to start your rails server- Goto http://localhost:3000/users/new to see a demo of the uploader
In your S3 Bucket you will need to add a CORS configuration. You can find this in the permissions tab of your S3 bucket. Learn more about CORS here.
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>