Class: Fog::Storage::Rackspace::File
- Defined in:
- lib/fog/rackspace/models/storage/file.rb
Instance Attribute Summary collapse
-
#access_control_allow_origin ⇒ String
A space delimited list of URLs allowed to make Cross Origin Requests.
-
#content_encoding ⇒ String
The content encoding of the file.
-
#content_length ⇒ Integer
readonly
The content length of the file.
-
#content_type ⇒ String
The MIME Media Type of the file.
-
#delete_after ⇒ Integer
A number of seconds representing how long from now this object will be automatically deleted.
-
#delete_at ⇒ Integer
A Unix Epoch Timestamp, in integer form, representing the time when this object will be automatically deleted.
-
#directory ⇒ Fog::Storage::Rackspace::Directory
Directory containing file.
-
#etag ⇒ String
The MD5 checksum of file.
-
#key ⇒ String
readonly
The name of the file.
-
#last_modified ⇒ Time
The last time the file was modified.
-
#origin ⇒ String
The origin is the URI of the object’s host.
- #public ⇒ Object writeonly
Attributes inherited from Model
Instance Method Summary collapse
-
#body ⇒ Object
Returns the body/contents of file.
-
#body=(new_body) ⇒ Object
Sets the body/contents of file.
-
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
Copy file to another directory or directory.
-
#destroy ⇒ Boolean
Destroy the file.
-
#ios_url ⇒ String
URL used to stream video to iOS devices without needing to convert your video.
-
#metadata ⇒ Fog::Storage::Rackspace::Metadata
File metadata.
-
#metadata=(hash) ⇒ Object
Set file metadata.
-
#owner=(new_owner) ⇒ Object
Required for compatibility with other Fog providers.
-
#public? ⇒ Boolean
Is file published to CDN.
-
#public_url ⇒ String
Returns the public url for the file.
-
#purge_from_cdn ⇒ Object
Immediately purge file from the CDN network.
-
#save(options = {}) ⇒ Object
Create or updates file and associated metadata.
-
#streaming_url ⇒ String
URL used to stream resources.
-
#url(expires, options = {}) ⇒ String
Get a url for file.
Methods inherited from Model
#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Attribute Details
#access_control_allow_origin ⇒ String
A space delimited list of URLs allowed to make Cross Origin Requests. Format is www.example.com. An asterisk (*) allows all.
38 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 38 attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin'] |
#content_encoding ⇒ String
Returns The content encoding of the file.
48 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 48 attribute :content_encoding, :aliases => 'Content-Encoding' |
#content_length ⇒ Integer (readonly)
Returns The content length of the file.
15 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 15 attribute :content_length, :aliases => ['bytes', 'Content-Length'], :type => :integer |
#content_type ⇒ String
Returns The MIME Media Type of the file.
20 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 20 attribute :content_type, :aliases => ['content_type', 'Content-Type'] |
#delete_after ⇒ Integer
A number of seconds representing how long from now this object will be automatically deleted.
60 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 60 attribute :delete_after, :aliases => ['X-Delete-After'] |
#delete_at ⇒ Integer
A Unix Epoch Timestamp, in integer form, representing the time when this object will be automatically deleted.
54 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 54 attribute :delete_at, :aliases => ['X-Delete-At'] |
#directory ⇒ Fog::Storage::Rackspace::Directory
Returns directory containing file.
64 65 66 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 64 def directory @directory end |
#etag ⇒ String
The MD5 checksum of file. If included file creation request, will ensure integrity of the file.
27 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 27 attribute :etag, :aliases => ['hash', 'Etag'] |
#key ⇒ String (readonly)
Returns The name of the file.
11 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 11 identity :key, :aliases => 'name' |
#last_modified ⇒ Time
The last time the file was modified
32 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 32 attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time |
#origin ⇒ String
Returns The origin is the URI of the object’s host.
43 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 43 attribute :origin, :aliases => ['Origin'] |
#public=(value) ⇒ Object (writeonly)
Required for compatibility with other Fog providers. Not Used.
68 69 70 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 68 def public=(value) @public = value end |
Instance Method Details
#body ⇒ Object
Returns the body/contents of file
79 80 81 82 83 84 85 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 79 def body attributes[:body] ||= if last_modified collection.get(identity).body else '' end end |
#body=(new_body) ⇒ Object
Sets the body/contents of file
89 90 91 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 89 def body=(new_body) attributes[:body] = new_body end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
Copy file to another directory or directory
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 102 def copy(target_directory_key, target_file_key, ={}) requires :directory, :key ['Content-Type'] ||= content_type if content_type ['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin ['Origin'] ||= origin if origin ['Content-Encoding'] ||= content_encoding if content_encoding service.copy_object(directory.key, key, target_directory_key, target_file_key, ) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.get(target_file_key) end |
#destroy ⇒ Boolean
Destroy the file
120 121 122 123 124 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 120 def destroy requires :directory, :key service.delete_object(directory.key, key) true end |
#ios_url ⇒ String
URL used to stream video to iOS devices without needing to convert your video
224 225 226 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 224 def ios_url Files::file_url directory.ios_url, key end |
#metadata ⇒ Fog::Storage::Rackspace::Metadata
File metadata
139 140 141 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 139 def attributes[:metadata] ||= Fog::Storage::Rackspace::Metadata.new(self) end |
#metadata=(hash) ⇒ Object
Set file metadata
128 129 130 131 132 133 134 135 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 128 def (hash) if hash.is_a? Fog::Storage::Rackspace::Metadata attributes[:metadata] = hash else attributes[:metadata] = Fog::Storage::Rackspace::Metadata.new(self, hash) end attributes[:metadata] end |
#owner=(new_owner) ⇒ Object
Required for compatibility with other Fog providers. Not Used.
144 145 146 147 148 149 150 151 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 144 def owner=(new_owner) if new_owner attributes[:owner] = { :display_name => new_owner['DisplayName'], :id => new_owner['ID'] } end end |
#public? ⇒ Boolean
Is file published to CDN
177 178 179 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 177 def public? directory.public? end |
#public_url ⇒ String
Returns the public url for the file. If the file has not been published to the CDN, this method will return nil as it is not publically accessible. This method will return the approprate url in the following order:
-
If the service used to access this file was created with the option :rackspace_cdn_ssl => true, this method will return the SSL-secured URL.
-
If the directory’s cdn_cname attribute is populated this method will return the cname.
-
return the default CDN url.
213 214 215 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 213 def public_url Files::file_url directory.public_url, key end |
#purge_from_cdn ⇒ Object
You may only PURGE up to 25 objects per day. Any attempt to purge more than this will result in a 498 status code error (Rate Limited).
Immediately purge file from the CDN network
246 247 248 249 250 251 252 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 246 def purge_from_cdn if public? service.cdn.purge(self) else false end end |
#save(options = {}) ⇒ Object
Create or updates file and associated metadata
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 261 def save( = {}) requires :body, :directory, :key ['Content-Type'] = content_type if content_type ['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin ['Origin'] = origin if origin ['Content-Disposition'] = content_disposition if content_disposition ['Etag'] = etag if etag ['Content-Encoding'] = content_encoding if content_encoding ['X-Delete-At'] = delete_at if delete_at ['X-Delete-After'] = delete_after if delete_after .merge!(.to_headers) data = service.put_object(directory.key, key, body, ) update_attributes_from(data) self.content_length = Fog::Storage.get_body_size(body) self.content_type ||= Fog::Storage.get_content_type(body) true end |
#streaming_url ⇒ String
URL used to stream resources
235 236 237 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 235 def streaming_url Files::file_url directory.streaming_url, key end |
#url(expires, options = {}) ⇒ String
This URL does not use the Rackspace CDN
Get a url for file.
required attributes: key
191 192 193 194 195 196 197 198 |
# File 'lib/fog/rackspace/models/storage/file.rb', line 191 def url(expires, = {}) requires :key if service.ssl? service.get_object_https_url(directory.key, key, expires, ) else service.get_object_http_url(directory.key, key, expires, ) end end |