Class: S3UploadTasks
- Inherits:
-
Volt::Task
- Object
- Volt::Task
- S3UploadTasks
- Defined in:
- app/s3_uploader/tasks/s3_upload_tasks.rb
Constant Summary collapse
- EXPIRE_TIME =
5 minutes
(60 * 5)
- S3_URL =
'http://s3.amazonaws.com'
- LIMIT =
100 MB
100 * 1024 * 1024
- BUCKETS =
Volt.config.s3.buckets
Instance Method Summary collapse
Instance Method Details
#sign(bucket_name, filename, mime_type) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/s3_uploader/tasks/s3_upload_tasks.rb', line 11 def sign(bucket_name, filename, mime_type) s3 = Volt.config.s3.to_h buckets = s3[:buckets] key = s3[:key] secret = s3[:secret] [:buckets, :key, :secret].each do |prop| unless s3[prop] raise "s3_upload configure issue: Please configure Volt.config.s3.#{prop.to_s}" end end unless buckets.include?(bucket_name) raise "The bucket passed in (#{bucket_name.inspect}) does not match the list of supported buckets" end extname = File.extname(filename) filename = "#{SecureRandom.uuid}#{extname}" upload_key = Pathname.new(filename).to_s creds = Aws::Credentials.new(Volt.config.s3.key, Volt.config.s3.secret) s3 = Aws::S3::Resource.new(region: 'us-east-1', credentials: creds) bucket = s3.bucket(bucket_name) obj = bucket.object(upload_key) params = { acl: 'public-read' } # params[:content_length] = LIMIT if LIMIT [obj.presigned_url(:put, params), obj.public_url] end |