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 @options = { :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 @options 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 36 37 38 |
# File 'lib/s3_cors_fileupload/rails/policy_helper.rb', line 20 def policy_document @policy_document ||= Base64.encode64( MultiJson.dump( { expiration: 10.hours.from_now.utc.iso8601(3), 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", ""] ] } ) ).gsub(/\n/, '') end |
#upload_signature ⇒ Object
sign our request by Base64 encoding the policy document.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/s3_cors_fileupload/rails/policy_helper.rb', line 41 def upload_signature @upload_signature ||= Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::SHA1.new, [:secret_access_key], self.policy_document ) ).gsub(/\n/, '') end |