Parent

Class/Module Index [+]

Quicksearch

Fog::Storage::Rackspace::File

Attributes

directory[RW]

@!attribute [r] directory @return [Fog::Storage::Rackspace::Directory] directory containing file

public[W]

@!attribute [w] public @note Required for compatibility with other Fog providers. Not Used.

Public Instance Methods

body() click to toggle source

Returns the body/contents of file @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @example Retrieve and download contents of Cloud Files object to file system

file_object = directory.files.get('germany.jpg')
File.open('germany.jpg', 'w') {|f| f.write(file_object.body) }

@see Fog::Storage::Rackspace::Files#get

# File lib/fog/rackspace/models/storage/file.rb, line 62
def body
  attributes[:body] ||= if last_modified
    collection.get(identity).body
  else
    ''
  end
end
body=(new_body) click to toggle source

Sets the body/contents of file @param [String,File] new_body contents of file

# File lib/fog/rackspace/models/storage/file.rb, line 72
def body=(new_body)
  attributes[:body] = new_body
end
copy(target_directory_key, target_file_key, options={}) click to toggle source

Copy file to another directory or directory @param [String] target_directory_key @param [String] target_file_key @param options [Hash] used to pass in file attributes @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @see docs.rackspace.com/files/api/v1/cf-devguide/content/Copy_Object-d1e2241.html

# File lib/fog/rackspace/models/storage/file.rb, line 85
def copy(target_directory_key, target_file_key, options={})
  requires :directory, :key
  options['Content-Type'] ||= content_type if content_type
  options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin
  options['Origin'] ||= origin if origin
  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.get(target_file_key)
end
destroy() click to toggle source

Destroy the file @return [Boolean] returns true if file is destroyed @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @see docs.rackspace.com/files/api/v1/cf-devguide/content/Delete_Object-d1e2264.html

# File lib/fog/rackspace/models/storage/file.rb, line 102
def destroy
  requires :directory, :key
  service.delete_object(directory.key, key)
  true
end
ios_url() click to toggle source

URL used to stream video to iOS devices without needing to convert your video @return [String] iOS URL @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @see docs.rackspace.com/files/api/v1/cf-devguide/content/iOS-Streaming-d1f3725.html

# File lib/fog/rackspace/models/storage/file.rb, line 169
def ios_url
  Files::file_url directory.ios_url, key
end
metadata() click to toggle source

File metadata @return [Fog::Storage::Rackspace::Metadata] metadata key value pairs.

# File lib/fog/rackspace/models/storage/file.rb, line 121
def metadata
  attributes[:metadata] ||= Fog::Storage::Rackspace::Metadata.new(self)
end
metadata=(hash) click to toggle source

Set file metadata @param [Hash,Fog::Storage::Rackspace::Metadata] hash contains key value pairs

# File lib/fog/rackspace/models/storage/file.rb, line 110
def metadata=(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) click to toggle source

Required for compatibility with other Fog providers. Not Used.

# File lib/fog/rackspace/models/storage/file.rb, line 126
def owner=(new_owner)
  if new_owner
    attributes[:owner] = {
      :display_name => new_owner['DisplayName'],
      :id           => new_owner['ID']
    }
  end
end
public?() click to toggle source

Is file published to CDN @return [Boolean] return true if published to CDN @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/models/storage/file.rb, line 141
def public?
  directory.public?
end
public_url() click to toggle source

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:

  1. 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.

  2. If the directory's cdn_cname attribute is populated this method will return the cname.

  3. return the default CDN url.

@return [String] public url for file @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/models/storage/file.rb, line 158
def public_url
  Files::file_url directory.public_url, key
end
purge_from_cdn() click to toggle source

Immediately purge file from the CDN network @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @note 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). @see docs.rackspace.com/files/api/v1/cf-devguide/content/Purge_CDN-Enabled_Objects-d1e3858.html

# File lib/fog/rackspace/models/storage/file.rb, line 191
def purge_from_cdn
  if public?
    service.cdn.purge(self)
  else
    false
  end
end
save(options = {}) click to toggle source

Create or updates file and associated metadata @param options [Hash] additional parameters to pass to Cloud Files @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @see docs.rackspace.com/files/api/v1/cf-devguide/content/Create_Update_Object-d1e1965.html

# File lib/fog/rackspace/models/storage/file.rb, line 206
def save(options = {})
  requires :body, :directory, :key
  options['Content-Type'] = content_type if content_type
  options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin
  options['Origin'] = origin if origin
  options['Content-Disposition'] = content_disposition if content_disposition
  options.merge!(metadata.to_headers)

  data = service.put_object(directory.key, key, body, options)
  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() click to toggle source

URL used to stream resources @return [String] streaming url @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError] @see docs.rackspace.com/files/api/v1/cf-devguide/content/Streaming-CDN-Enabled_Containers-d1f3721.html

# File lib/fog/rackspace/models/storage/file.rb, line 180
def streaming_url
  Files::file_url directory.streaming_url, key
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.