Skip to content

Instantly share code, notes, and snippets.

@samwgoldman
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samwgoldman/9610193 to your computer and use it in GitHub Desktop.
Save samwgoldman/9610193 to your computer and use it in GitHub Desktop.
access_key_id = ENV.fetch("APP_S3_ACCESS_KEY_ID")
secret_access_key = ENV.fetch("APP_S3_SECRET_ACCESS_KEY")
bucket_name = ENV.fetch("APP_S3_BUCKET")
s3 = AWS::S3.new(access_key_id: access_key_id, secret_access_key: secret_access_key)
bucket = s3.buckets[bucket_name]
object = bucket.objects["whatever/you/want"]
presign = AWS::S3::PresignV4.new(object)
presign.presign(:put, expires: 15.minutes.from_now.to_i)
# => #<URI::HTTP:0x007fcfcd97e1a0 URL:***stuff***>
# Note: When I did this, I got back a URL like http://host:443/... but I had to change it to
# https://host/ for the signed property to match. Seems like a bug with aws-sdk.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment