Class: Fog::Backblaze::Storage::File
- Inherits:
-
Model
- Object
- Model
- Fog::Backblaze::Storage::File
- Defined in:
- lib/fog/backblaze/storage/models/file.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
Instance Method Summary collapse
-
#body ⇒ Object
TODO: read content from cloud on demand.
- #body=(new_body) ⇒ Object
- #destroy ⇒ Object
- #public_url ⇒ Object
- #save(options = {}) ⇒ Object
Instance Attribute Details
#directory ⇒ Object
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
#body ⇒ Object
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 |
#destroy ⇒ Object
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_url ⇒ Object
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( = {}) requires :body, :directory, :key [:content_type] = content_type if content_type data = service.put_object(directory.key, key, body, ) 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 |