eprothro
3/10/2017 - 11:28 PM

s3_direct_uploading.rb

module S3DirectUploading
  extend ActiveSupport::Concern

  included do
    S3_UPLOAD_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_UPLOAD_BUCKET'])

    helper_method :build_s3_direct_post
  end

  protected

  def build_s3_direct_post
    S3_UPLOAD_BUCKET.presigned_post(key: "web_uploads/#{SecureRandom.uuid}/${filename}", 
                                    success_action_status: '201', 
                                    acl: 'public-read', 
                                    content_type_starts_with: "")
  end
end