FlatironS3Uploader
A tool for resizing and uploading images to AWS S3.
Installation
$ gem install flatiron-s3-uploader
Configuration
The S3 upload functionality requires that you have the following environment variables set:
ENV['AWS_ACCESS_KEY_ID']
ENV['AWS_SECRET_ACCESS_KEY']
ENV['AWS_REGION']
Usage
The core functionality of uploading (and optionally resizing) images can be
performed one of two ways. To use this Ruby gem in other Ruby projects, use the
FlatironS3Uploader.upload
method directly:
# Upload a file to a specified S3 bucket
FlatironS3Uploader.upload('path/to/image.png', 'bucket-name')
# => "https://bucket-name.s3.amazonaws.com/image.png"
# Upload and resize an image
FlatironS3Uploader.upload('path/to/image.png', 'bucket-name', { width: 400, directory: 'folder/subfolder' })
# => "https://bucket-name.s3.amazonaws.com/folder/subfolder/image.png"
The FlatironS3Uploader.upload(path, bucket, options = {})
method takes the
following parameters:
path
: The file location of the image to be uploaded.bucket
: The name of the S3 bucket.options
:width
: The width of the resized image. If a +height+ is not specified, the height will scale based on the specified width.height
: The height of the resized image. If a +width+ is not specified, the width will scale based on the specified height.directory
: The directory of the S3 bucket to upload to (i.e. 'phase-3/lab-name')
You can also use the gem directly from the command line:
$ flatiron-s3-uploader upload path/to/image.png --bucket bucket-name --width 400 --directory folder/subfolder
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run
bundle exec rspec
to run the tests. You can also run bin/console
for an
interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To
release a new version, update the version number in version.rb
, and then run
bundle exec rake release
, which will create a git tag for the version, push
git commits and the created tag, and push the .gem
file to
rubygems.org.
This project uses Rubocop to enforce consistent styling
via a pre-commit hook, so any time you
make a commit, your code will be linted. For VSCode users, it's suggested that
you install the
Ruby VSCode extension
and enable linting in VSCode via the settings.json
file so that you can see
linting errors before committing your code:
{
"ruby.lint": {
"rubocop": {
"useBundler": true
}
},
"ruby.format": "rubocop"
}
You can also run Rubocop manually to get a list of any issues:
$ bundle exec rubocop
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ihollander/flatiron-s3-uploader. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the FlatironS3Uploader project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.