Class: PostToS3::FileUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/post_to_s3/file_upload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FileUpload

Returns a new instance of FileUpload.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/post_to_s3/file_upload.rb', line 8

def initialize(options = {})
  @bucket_url = options[:bucket_url]
  @key = options[:key]
  @policy = options[:policy]

  if @policy
    @policy['expiration'] = @policy['expiration'].utc

    @conditions =
      @policy['conditions'].map {|condition| condition.to_a.flatten }

    @acl, @success_action_redirect =
      Hash[@conditions].values_at('acl', 'success_action_redirect')

    @policy =
      Base64.encode64(ActiveSupport::JSON.encode(@policy)).gsub("\n", '')
  end
end

Instance Attribute Details

#aclObject (readonly)

Returns the value of attribute acl.



5
6
7
# File 'lib/post_to_s3/file_upload.rb', line 5

def acl
  @acl
end

#bucket_urlObject (readonly)

Returns the value of attribute bucket_url.



5
6
7
# File 'lib/post_to_s3/file_upload.rb', line 5

def bucket_url
  @bucket_url
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



5
6
7
# File 'lib/post_to_s3/file_upload.rb', line 5

def conditions
  @conditions
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/post_to_s3/file_upload.rb', line 5

def key
  @key
end

#policyObject (readonly)

Returns the value of attribute policy.



5
6
7
# File 'lib/post_to_s3/file_upload.rb', line 5

def policy
  @policy
end

#success_action_redirectObject (readonly)

Returns the value of attribute success_action_redirect.



5
6
7
# File 'lib/post_to_s3/file_upload.rb', line 5

def success_action_redirect
  @success_action_redirect
end

Instance Method Details

#access_key_idObject



27
28
29
# File 'lib/post_to_s3/file_upload.rb', line 27

def access_key_id
  config.access_key_id
end

#signatureObject



31
32
33
34
35
36
37
38
# File 'lib/post_to_s3/file_upload.rb', line 31

def signature
  Base64.encode64(
    OpenSSL::HMAC.digest(
      OpenSSL::Digest::Digest.new('sha1'),
      config.secret_access_key,
      policy
  )).gsub("\n", '')
end