Class: S3DirectUpload

Inherits:
Object
  • Object
show all
Includes:
S3SwfUpload::Signature
Defined in:
lib/forge/app/models/s3_direct_upload.rb,
lib/forge/spec/controllers/forge/videos_controller_spec.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

#initializeS3DirectUpload

Returns a new instance of S3DirectUpload.



6
7
8
9
10
11
12
13
# File 'lib/forge/app/models/s3_direct_upload.rb', line 6

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.



4
5
6
# File 'lib/forge/app/models/s3_direct_upload.rb', line 4

def access_key_id
  @access_key_id
end

#bucketObject

Returns the value of attribute bucket.



4
5
6
# File 'lib/forge/app/models/s3_direct_upload.rb', line 4

def bucket
  @bucket
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/forge/app/models/s3_direct_upload.rb', line 4

def options
  @options
end

#secret_access_keyObject

Returns the value of attribute secret_access_key.



4
5
6
# File 'lib/forge/app/models/s3_direct_upload.rb', line 4

def secret_access_key
  @secret_access_key
end

Instance Method Details

#post_paramsObject



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

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



31
32
33
# File 'lib/forge/app/models/s3_direct_upload.rb', line 31

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