Class: S3UploadsController

Inherits:
ApplicationController
  • Object
show all
Includes:
S3SwfUpload::Signature
Defined in:
lib/s3_swf_upload/railties/generators/uploader/templates/s3_uploads_controller.rb

Instance Method Summary collapse

Methods included from S3SwfUpload::Signature

#assert, #b64_hmac_sha1, #binb2b64, #binb2hex, #core_hmac_sha1, #core_sha1, #hex_sha1, #rol, #safe_add, #self_test, #sha1_ft, #sha1_kt, #str2binb

Instance Method Details

#indexObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/s3_swf_upload/railties/generators/uploader/templates/s3_uploads_controller.rb', line 11

def index
  bucket          = S3SwfUpload::S3Config.bucket
  access_key_id   = S3SwfUpload::S3Config.access_key_id
  acl             = S3SwfUpload::S3Config.acl
  secret_key      = S3SwfUpload::S3Config.secret_access_key
  key             = params[:key]
  content_type    = params[:content_type]
  https           = 'false'
  error_message   = ''
  expiration_date = 1.hours.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')

  policy = Base64.encode64(
"{
  'expiration': '#{expiration_date}',
  'conditions': [
      {'bucket': '#{bucket}'},
      {'key': '#{key}'},
      {'acl': '#{acl}'},
      {'Content-Type': '#{content_type}'},
      {'Content-Disposition': 'attachment'},
      ['starts-with', '$Filename', ''],
      ['eq', '$success_action_status', '201']
  ]
}").gsub(/\n|\r/, '')

  signature = b64_hmac_sha1(secret_key, policy)

  respond_to do |format|
    format.xml {
      render :xml => {
        :policy          => policy,
        :signature       => signature,
        :bucket          => bucket,
        :accesskeyid     => access_key_id,
        :acl             => acl,
        :expirationdate  => expiration_date,
        :https           => https,
        :errorMessage    => error_message.to_s
      }.to_xml
    }
  end
end