module FlatironS3Uploader
Constants
- VERSION
Public Class Methods
upload(filepath, bucket, options = {})
click to toggle source
Uploads an image file from the specified filepath to the specified S3 bucket. Returns a URL for the uploaded image.
Options are:
- :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’)
Examples:
FlatironS3Uploader.upload('path/to/image.png', 'bucket-name', { width: 400 }) # => "https://bucket-name.s3.amazonaws.com/image.png" FlatironS3Uploader.upload('path/to/image.png', 'bucket-name', { width: 400, directory: 'folder/subfolder' }) # => "https://bucket-name.s3.amazonaws.com/folder/subfolder/image.png"
# File lib/flatiron_s3_uploader.rb, line 34 def self.upload(filepath, bucket, options = {}) resizer = ImageResizer.new(filepath) filepath = resizer.resize(width: options[:width], height: options[:height]) if options[:width] || options[:height] mime_type = resizer.mime_type image = File.open(filepath) client = Aws::S3::Client.new FileUploader.new(client).upload(bucket, image, mime_type, options[:directory]) end