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


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

def body
  attributes[:body] ||= begin
    response = service.get_object(directory.key, file_name)
    response.body
  end
end

#body=(new_body) ⇒ Object


22
23
24
# File 'lib/fog/backblaze/storage/models/file.rb', line 22

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

#copy(target_directory_key, target_file_key, options = {}) ⇒ Object


65
66
67
68
69
70
71
# File 'lib/fog/backblaze/storage/models/file.rb', line 65

def copy(target_directory_key, target_file_key, options = {})
  requires :directory, :key

  service.copy_object(directory.key, key, target_directory_key, target_file_key, options)
  target_directory = service.directories.new(key: target_directory_key)
  target_directory.files.head(target_file_key)
end

#destroyObject


46
47
48
49
50
51
52
# File 'lib/fog/backblaze/storage/models/file.rb', line 46

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

#public_urlObject


54
55
56
57
58
# File 'lib/fog/backblaze/storage/models/file.rb', line 54

def public_url
  requires :directory, :key

  service.get_object_url(directory.key, key)
end

#save(options = {}) ⇒ Object


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

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)

  attributes.delete(:body)

  true
end

#url(expires) ⇒ Object


60
61
62
63
# File 'lib/fog/backblaze/storage/models/file.rb', line 60

def url(expires)
 requires :key
 collection.get_https_url(key, expires)
end