Skip to content

Instantly share code, notes, and snippets.

@TonsOfFun
Created May 14, 2018 17:36
Show Gist options
  • Select an option

  • Save TonsOfFun/a0c54ba08cb81eb7a07543dd6b41d82d to your computer and use it in GitHub Desktop.

Select an option

Save TonsOfFun/a0c54ba08cb81eb7a07543dd6b41d82d to your computer and use it in GitHub Desktop.
Crypto Smart Camera: Pre-signed POST to S3
module RequestSigning
extend ActiveSupport::Concern
included do
before_action :set_s3_direct_post, only: [:new]
end
def set_s3_direct_post
@s3_direct_post = AWS_S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
end
end
@TonsOfFun

Copy link
Copy Markdown
Author

This concern provides a callback which can be used in a controller to populate a form for direct S3 file uploads

    <%= form_for(note, html: {
        class: 'direct-upload',
        data: {
          'form-data' => (@s3_direct_post.fields),
          'url' => @s3_direct_post.url,
          'host' => URI.parse(@s3_direct_post.url).host
          }
        }) do |note_form| %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment