28 lines
826 B
Ruby
28 lines
826 B
Ruby
require 'aws-sdk'
|
|
require 'active_support/all'
|
|
|
|
module JamRuby
|
|
class S3Util
|
|
@@def_opts = { :expires => 3600 * 24, :secure => true } # 24 hours from now
|
|
@@s3 = AWS::S3.new(:access_key_id => ENV['AWS_KEY'], :secret_access_key => ENV['AWS_SECRET'])
|
|
|
|
def self.sign_url(bucket, path, options = @@def_opts)
|
|
bucket_gen = @@s3.buckets[bucket]
|
|
"#{bucket_gen.objects[path].url_for(:read, options).to_s}"
|
|
end
|
|
|
|
def self.url(aws_bucket, filename, options = @@def_opts)
|
|
"http#{options[:secure] ? "s" : ""}://s3.amazonaws.com/#{aws_bucket}/#{filename}"
|
|
end
|
|
|
|
def self.move(aws_bucket, source, destination)
|
|
@@s3.buckets[aws_bucket].objects[source].move_to[destination]
|
|
end
|
|
|
|
def self.delete(aws_bucket, path)
|
|
@@s3.buckets[aws_bucket].objects[path].delete()
|
|
end
|
|
end
|
|
end
|
|
|