Class: Tenon::S3DirectUpload

Inherits:
Object
  • Object
show all
Includes:
S3SwfUpload::Signature
Defined in:
app/models/tenon/s3_direct_upload.rb

Instance Attribute Summary collapse

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

Constructor Details

#initialize(opts = {}) ⇒ S3DirectUpload

Returns a new instance of S3DirectUpload.



7
8
9
10
11
12
13
14
# File 'app/models/tenon/s3_direct_upload.rb', line 7

def initialize(opts = {})
  self.options           = default_options.merge(opts.symbolize_keys)

  config                 = YAML.load_file(options[:config_file])
  self.bucket            = config[Rails.env]['bucket']
  self.access_key_id     = config[Rails.env]['access_key_id']
  self.secret_access_key = config[Rails.env]['secret_access_key']
end

Instance Attribute Details

#access_key_idObject

Returns the value of attribute access_key_id.



5
6
7
# File 'app/models/tenon/s3_direct_upload.rb', line 5

def access_key_id
  @access_key_id
end

#bucketObject

Returns the value of attribute bucket.



5
6
7
# File 'app/models/tenon/s3_direct_upload.rb', line 5

def bucket
  @bucket
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'app/models/tenon/s3_direct_upload.rb', line 5

def options
  @options
end

#secret_access_keyObject

Returns the value of attribute secret_access_key.



5
6
7
# File 'app/models/tenon/s3_direct_upload.rb', line 5

def secret_access_key
  @secret_access_key
end

Instance Method Details

#post_paramsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/tenon/s3_direct_upload.rb', line 16

def post_params
  {
    'key' => "#{options[:key]}/#{time}-${filename}",
    'AWSAccessKeyId' => "#{access_key_id}",
    'acl' => "#{options[:acl]}",
    'policy' => "#{policy}",
    'signature' => "#{signature}",
    'success_action_status' => '201',
    '__utma' => '1',
    '__utmb' => '1',
    '__utmc' => '1',
    '__utmz' => '1',
    'auth_token' => '1'
  }
end

#upload_urlObject



32
33
34
# File 'app/models/tenon/s3_direct_upload.rb', line 32

def upload_url
  "http://#{bucket}.s3.amazonaws.com/"
end