Module: DirectWave::Uploader::Accreditation

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/directwave/uploader/accreditation.rb

Instance Method Summary collapse

Instance Method Details

#s3_aclObject

Returns

String

Amazon S3 acl



12
13
14
# File 'lib/directwave/uploader/accreditation.rb', line 12

def s3_acl
  @s3_acl ||= s3_access_policy.to_s.gsub("_", "-")
end

#s3_policyObject

Returns

Boolean

Amazon S3 policy



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/directwave/uploader/accreditation.rb', line 21

def s3_policy
  @s3_policy ||= Base64.encode64(
    {
      "expiration" => (Time.now + expiration_period).utc.iso8601,
      "conditions" => [
        {"bucket" => s3_bucket},
        ["starts-with", "$key", upload_dir],
        {"acl" => s3_acl},
        {"success_action_status" => "201"},
        ["content-length-range", 0, max_file_size],
        ["starts-with", "$Filename", ""],
        ['starts-with', '#{content_type}', '']
      ]
    }.to_json
  ).gsub("\n","")
end

#s3_signatureObject

Returns

Boolean

Amazon S3 signature



43
44
45
46
47
48
49
50
# File 'lib/directwave/uploader/accreditation.rb', line 43

def s3_signature
  @s3_signature ||= Base64.encode64(
    OpenSSL::HMAC.digest(
      OpenSSL::Digest::Digest.new("sha1"), 
      s3_secret_access_key, s3_policy
    )
  ).gsub("\n","")
end