Skip to content

Instantly share code, notes, and snippets.

@danielwestendorf
Last active October 2, 2016 17:10
Show Gist options
  • Save danielwestendorf/2a42ee25074e99020eca7870886116c0 to your computer and use it in GitHub Desktop.
Save danielwestendorf/2a42ee25074e99020eca7870886116c0 to your computer and use it in GitHub Desktop.
class Upload < ApplicationRecord
validates :size, inclusion: { in: 0..2.megabytes }
def key
"#{id}/#{filename}"
end
def url
bucket.object(key).presigned_url(:get, expires_in: 604_800)
end
def bucket
@bucket ||= Aws::S3::Resource.new.bucket(ENV["AWS_S3_BUCKET"])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment