Skip to content

Instantly share code, notes, and snippets.

@nikasulo
Created February 27, 2020 01: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 nikasulo/0ae8234ec2c86cedff8d8cf59071566d to your computer and use it in GitHub Desktop.
Save nikasulo/0ae8234ec2c86cedff8d8cf59071566d to your computer and use it in GitHub Desktop.
class S3UploadsController < ApplicationController
def set_s3_direct_post
filename = params[:filename]
file_type = params[:fileType]
directory = params[:directory]
random_path = SecureRandom.uuid
key = "uploads/#{directory}/#{random_path}/#{filename}"
signer = Aws::S3::Presigner.new
post_url = signer.presigned_url(:put_object, bucket: "damilare-api", key: key, acl: 'public-read', content_type: file_type)
get_url = "https://damilare-api.s3-us-west-1.amazonaws.com/#{key}"
json_response(
{
post_url: post_url,
get_url: get_url,
}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment