Class: EchoUploads::S3Store

Inherits:
AbstractStore show all
Defined in:
lib/echo_uploads/s3_store.rb

Instance Method Summary collapse

Instance Method Details

#delete(key) ⇒ Object



6
7
8
# File 'lib/echo_uploads/s3_store.rb', line 6

def delete(key)
  bucket.object(path(key)).delete
end

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/echo_uploads/s3_store.rb', line 10

def exists?(key)
  bucket.object(path(key)).exists?
end

#read(key) ⇒ Object



14
15
16
# File 'lib/echo_uploads/s3_store.rb', line 14

def read(key)
  bucket.object(path(key)).get.body.read
end

#url(key, options = {}) ⇒ Object



18
19
20
21
# File 'lib/echo_uploads/s3_store.rb', line 18

def url(key, options = {})
  options = {method: :get}.merge(options)
  bucket.object(path(key)).presigned_url options.delete(:method), options
end

#write(key, file, metadata) ⇒ Object



23
24
25
26
# File 'lib/echo_uploads/s3_store.rb', line 23

def write(key, file, )
  file.rewind
  bucket.object(path(key)).put body: file, content_type: .mime_type
end