Class: Fog::Backblaze::Storage::File

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/backblaze/storage/models/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



11
12
13
# File 'lib/fog/backblaze/storage/models/file.rb', line 11

def directory
  @directory
end

Instance Method Details

#bodyObject

TODO: read content from cloud on demand



16
17
18
# File 'lib/fog/backblaze/storage/models/file.rb', line 16

def body
  attributes[:body] #||= file_id && (file = collection.get(identity)) ? file.body : ""
end

#body=(new_body) ⇒ Object



20
21
22
# File 'lib/fog/backblaze/storage/models/file.rb', line 20

def body=(new_body)
  attributes[:body] = new_body
end

#destroyObject



42
43
44
45
46
47
48
# File 'lib/fog/backblaze/storage/models/file.rb', line 42

def destroy
  requires :key
  response = service.delete_object(directory.key, key)
  return response.status < 400
#rescue Fog::Errors::NotFound
#  false
end

#public_urlObject



50
51
52
53
54
# File 'lib/fog/backblaze/storage/models/file.rb', line 50

def public_url
  requires :directory, :key

  service.get_object_url(directory.key, key)
end

#save(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/backblaze/storage/models/file.rb', line 27

def save(options = {})
  requires :body, :directory, :key

  options[:content_type] = content_type if content_type

  data = service.put_object(directory.key, key, body, options)

  merge_attributes(data.headers.reject { |key, _value| %w(contentLength contentType).include?(key) })

  self.content_length = Fog::Storage.get_body_size(body)
  self.content_type ||= Fog::Storage.get_content_type(body)

  true
end