Class: Attach::S3::Backend

Inherits:
Backends::Abstract
  • Object
show all
Defined in:
lib/attach/s3/backend.rb

Instance Method Summary collapse

Instance Method Details

#delete(attachment) ⇒ Object



24
25
26
27
28
29
# File 'lib/attach/s3/backend.rb', line 24

def delete(attachment)
  s3 = setup_s3_request
  path = path_for_attachment(attachment)

  s3.bucket(@config[:bucket]).object(path).delete
end

#read(attachment) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/attach/s3/backend.rb', line 9

def read(attachment)
  s3 = setup_s3_request
  path = path_for_attachment(attachment)

  resp = s3.bucket(@config[:bucket]).object(path).get
  resp.body.read
end

#write(attachment, data) ⇒ Object



17
18
19
20
21
22
# File 'lib/attach/s3/backend.rb', line 17

def write(attachment, data)
  s3 = setup_s3_request
  path = path_for_attachment(attachment)

  s3.bucket(@config[:bucket]).object(path).put(body: attachment.binary)
end