Skip to content

Instantly share code, notes, and snippets.

@matthewlehner
Last active December 22, 2015 21:19
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 matthewlehner/6532853 to your computer and use it in GitHub Desktop.
Save matthewlehner/6532853 to your computer and use it in GitHub Desktop.
def upload(filename, file_location)
bucket = AWS::S3::Bucket.new(ENV["AWS_BUCKET_NAME"])
key = "uploads/#{SecureRandom.uuid}/#{filename}"
content_type = MIME::Types.type_for(filename).first.to_s
presigned_post = bucket.presigned_post(key: key, content_type: content_type)
url = presigned_post.url.to_s
fields = presigned_post.fields
`curl -i -v -X POST -F "AWSAccessKeyId=#{fields['AWSAccessKeyId']}" -F "key=#{fields['key']}" -F "policy=#{fields['policy']}" -F "signature=#{fields['signature']}" -F "Content-Type=#{content_type}" -F "file=@#{file_location + filename}" '#{url}'`
end
@matthewlehner
Copy link
Author

This version works!

def upl(filename, file_location)
  bucket = AWS::S3::Bucket.new(ENV["AWS_BUCKET_NAME"])
  key = "uploads/#{SecureRandom.uuid}/#{filename}"
  content_type = MIME::Types.type_for(filename).first.to_s
  presigned_post = bucket.presigned_post(key: key, content_type: content_type)
  url = presigned_post.url.to_s
  fields = presigned_post.fields
  `curl -i -v -X POST -F "AWSAccessKeyId=#{fields['AWSAccessKeyId']}" -F "key=#{fields['key']}" -F "policy=#{fields['policy']}" -F "signature=#{fields['signature']}" -F "Content-Type=#{content_type}" -F "file=@#{file_location + filename}" '#{url}'`
end

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