Class: S3CorsFileupload::PolicyHelper
- Inherits:
-
Object
- Object
- S3CorsFileupload::PolicyHelper
- Defined in:
- lib/s3_cors_fileupload/rails/policy_helper.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(_options = {}) ⇒ PolicyHelper
constructor
A new instance of PolicyHelper.
-
#policy_document ⇒ Object
generate the policy document that amazon is expecting.
-
#upload_signature ⇒ Object
sign our request by Base64 encoding the policy document.
Constructor Details
#initialize(_options = {}) ⇒ PolicyHelper
Returns a new instance of PolicyHelper.
10 11 12 13 14 15 16 17 |
# File 'lib/s3_cors_fileupload/rails/policy_helper.rb', line 10 def initialize( = {}) # default max_file_size to 500 MB if nothing is received = { :acl => 'public-read', :max_file_size => Config.max_file_size || 524288000, :bucket => Config.bucket }.merge().merge(:secret_access_key => Config.secret_access_key) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/s3_cors_fileupload/rails/policy_helper.rb', line 8 def end |
Instance Method Details
#policy_document ⇒ Object
generate the policy document that amazon is expecting.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/s3_cors_fileupload/rails/policy_helper.rb', line 20 def policy_document Base64.encode64( { expiration: 1.hour.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z'), conditions: [ { bucket: [:bucket] }, { acl: [:acl] }, { success_action_status: '201' }, ["content-length-range", 0, [:max_file_size]], ["starts-with", "$utf8", ""], ["starts-with", "$key", ""], ["starts-with", "$Content-Type", ""] ] }.to_json ).gsub(/\n|\r/, '') end |
#upload_signature ⇒ Object
sign our request by Base64 encoding the policy document.
38 39 40 41 42 43 44 45 46 |
# File 'lib/s3_cors_fileupload/rails/policy_helper.rb', line 38 def upload_signature Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::Digest.new('sha1'), [:secret_access_key], self.policy_document ) ).gsub(/\n/, '') end |