Class: Fog::Storage::Aliyun::File
- Inherits:
-
Model
- Object
- Model
- Fog::Storage::Aliyun::File
- Defined in:
- lib/fog/aliyun/models/storage/file.rb
Instance Method Summary collapse
- #body ⇒ Object
- #body=(new_body) ⇒ Object
- #copy(target_directory_key, target_file_key, options = {}) ⇒ Object
- #destroy ⇒ Object
- #directory ⇒ Object
- #metadata ⇒ Object
- #owner=(new_owner) ⇒ Object
- #public=(new_public) ⇒ Object
- #public_url ⇒ Object
- #save(options = {}) ⇒ Object
-
#url(expires, options = {}) ⇒ String
Get a url for file.
Instance Method Details
#body ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 19 def body attributes[:body] ||= if last_modified collection.get(identity).body else '' end end |
#body=(new_body) ⇒ Object
27 28 29 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 27 def body=(new_body) attributes[:body] = new_body end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 35 def copy(target_directory_key, target_file_key, ={}) requires :directory, :key if directory.key == "" source_object = key else source_object = directory.key+"/"+key end if target_directory_key == "" target_object = target_file_key else target_object = target_directory_key+"/"+target_file_key end service.copy_object(nil, source_object, nil, target_object, ) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.get(target_file_key) end |
#destroy ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 52 def destroy requires :directory, :key if directory.key == "" object = key else object = directory.key+"/"+key end service.delete_object(object) true end |
#directory ⇒ Object
31 32 33 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 31 def directory @directory end |
#metadata ⇒ Object
63 64 65 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 63 def attributes[:metadata] ||= end |
#owner=(new_owner) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 67 def owner=(new_owner) if new_owner attributes[:owner] = { :display_name => new_owner['DisplayName'], :id => new_owner['ID'] } end end |
#public=(new_public) ⇒ Object
76 77 78 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 76 def public=(new_public) new_public end |
#public_url ⇒ Object
98 99 100 101 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 98 def public_url requires :key self.collection.get_url(self.key) end |
#save(options = {}) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 103 def save( = {}) requires :body, :directory, :key ['Content-Type'] = content_type if content_type ['Content-Disposition'] = content_disposition if content_disposition ['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin ['Origin'] = origin if origin .merge!() if directory.key == "" object = key else object = directory.key+"/"+key end if body.is_a?(::File) data = service.put_object(object, body, ).data elsif body.is_a?(String) data = service.put_object_with_body(object, body, ).data else raise Fog::Storage::Aliyun::Error, " Forbidden: Invalid body type: #{body.class}!" end update_attributes_from(data) self.content_length = Fog::Storage.get_body_size(body) self.content_type ||= Fog::Storage.get_content_type(body) true end |
#url(expires, options = {}) ⇒ String
Get a url for file.
required attributes: directory, key
88 89 90 91 92 93 94 95 96 |
# File 'lib/fog/aliyun/models/storage/file.rb', line 88 def url(expires, = {}) requires :directory, :key if directory.key == "" object = key else object = directory.key+"/"+key end self.service.get_object_http_url_public(object, expires, ) end |