This Sinatra web app works as follows:
- Prompts the user for an image file to upload (via a form)
- Writes the image to a local temp directory (./public/tmp)
- Uploads the image to the specified AWS S3 bucket
- Deletes the image from the local temp directory
- Generates a secure URL to the uploaded image in the S3 bucket
- Renders the image from the S3 bucket using the secure URL
In order to use this app, you should do the following:
-
Run the following command to install the aws-sdk gem:
gem install aws-sdk
-
Create an AWS S3 bucket.
-
Create an IAM user with access limited to S3.
-
Document the access key ID and secret access key for the user.
-
Create a local_env.rb file with the access key ID and secret access key
- see /lib/local_env.rb.sample for example
Resources
To run the app locally:
-
Make sure that Ruby is installed.
-
Make sure that the Sinatra gem is installed. Note that installing the Sinatra gem will install other gems necessary to run the app locally, such as rack.
-
Navigate to the directory which contains app.rb in a terminal (command prompt) session.
-
Run the following command to launch the Sinatra web server:
ruby app.rb
To open the app locally once it is running via ruby, use the following URL: