Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Created March 2, 2016 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aupajo/e1ead99b677b307d03ed to your computer and use it in GitHub Desktop.
Save Aupajo/e1ead99b677b307d03ed to your computer and use it in GitHub Desktop.
Uploading to S3 without a server in Rails
<% post = Aws::S3::Bucket.new(ENV.fetch('AWS_S3_BUCKET')).presigned_post(key: 'uploads/${filename}', acl: 'public-read') %>
<%= form_tag(post.url, id: 'uploader', multipart: true, authenticity_token: false, enforce_utf8: false) do %>
<% post.fields.each do |name, value| %>
<%= text_field_tag name, value %>
<% end %>
<% # Must be last field %>
<%= file_field_tag :file %>
<input type="submit" value="Upload">
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment