Class: Vzaar::Uploaders::S3

Inherits:
Struct
  • Object
show all
Defined in:
lib/vzaar/uploaders/s3.rb

Constant Summary collapse

SEND_TIMEOUT =
1800

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



3
4
5
# File 'lib/vzaar/uploaders/s3.rb', line 3

def path
  @path
end

#signatureObject

Returns the value of attribute signature

Returns:

  • (Object)

    the current value of signature



3
4
5
# File 'lib/vzaar/uploaders/s3.rb', line 3

def signature
  @signature
end

Instance Method Details

#uploadObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vzaar/uploaders/s3.rb', line 6

def upload
  client = HTTPClient.new
  client.send_timeout = SEND_TIMEOUT
  begin
    file = File.open(path)
    res = client.post url, [
      ['acl', signature.acl],
      ['bucket', signature.bucket],
      ['success_action_status', '201'],
      ['policy', signature.policy],
      ['AWSAccessKeyId', signature.access_key_id],
      ['signature', signature.signature],
      ['key', signature.key],
      ['file', file]
    ]
  ensure
    file.close if file
  end
  res.status_code == 201
end

#urlObject



27
28
29
# File 'lib/vzaar/uploaders/s3.rb', line 27

def url
  "https://#{signature.bucket}.s3.amazonaws.com/"
end