Repository URL to install this package:
|
Version:
2.23.0 ▾
|
class S3Service
attr_reader :bucket, :key, :policy, :signature
# based on https://github.com/iwasrobbed/Rails3-S3-Uploader-Plupload/blob/master/app/helpers/uploads_helper.rb
def initialize(project_id)
spec = Gem::Specification.find_by_name("j_platform")
@bucket = S3_CONFIG[:BUCKET]
@key = S3_CONFIG[:KEY]
secret = S3_CONFIG[:SECRET]
@policy = Base64.encode64(
"{'expiration': '#{10.hours.from_now.utc.iso8601}',
'conditions': [
{'bucket': '#{@bucket}'},
{'acl': 'public-read'},
{'success_action_status': '201'},
['content-length-range', 0, #{100.megabytes}],
['starts-with', '$key', '#{project_id}/'],
['starts-with', '$Content-Type', ''],
['starts-with', '$name', ''],
['starts-with', '$filename', '']
]
}").gsub(/\n|\r/, '')
@signature = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
secret, @policy)).gsub("\n","")
end
end