Class CloudFiles::StorageObject
In: lib/cloudfiles/storage_object.rb
Parent: Object

Methods

Attributes

bytes  [R]  Size of the object (in bytes)
container  [R]  The parent CloudFiles::Container object
content_type  [R]  Content type of the object data
etag  [R]  ETag of the object data
last_modified  [R]  Date of the object‘s last modification
name  [R]  Name of the object corresponding to the instantiated object

Public Class methods

Builds a new CloudFiles::StorageObject in the current container. If force_exist is set, the object must exist or a NoSuchObjectException will be raised. If not, an "empty" CloudFiles::StorageObject will be returned, ready for data via CloudFiles::StorageObject.write

Public Instance methods

Retrieves the data from an object and stores the data in memory. The data is returned as a string. Throws a NoSuchObjectException if the object doesn‘t exist.

If the optional size and range arguments are provided, the call will return the number of bytes provided by size, starting from the offset provided in offset.

  object.data
  => "This is the text stored in the file"

Retrieves the data from an object and returns a stream that must be passed to a block. Throws a NoSuchObjectException if the object doesn‘t exist.

If the optional size and range arguments are provided, the call will return the number of bytes provided by size, starting from the offset provided in offset.

  data = ""
  object.data_stream do |chunk|
    data += chunk
  end

  data
  => "This is the text stored in the file"

A convenience method to stream data into an object from a local file (or anything that can be loaded by Ruby‘s open method)

Throws an Errno::ENOENT if the file cannot be read.

  object.data
  => "This is my data"

  object.load_from_filename("/tmp/file.txt")
  => true

  object.data
  => "This data was in the file /tmp/file.txt"

  object.load_from_filename("/tmp/nonexistent.txt")
  => Errno::ENOENT: No such file or directory - /tmp/nonexistent.txt

Returns the object‘s metadata as a nicely formatted hash, stripping off the X-Meta-Object- prefix that the system prepends to the key name.

   object.metadata
   => {"ruby"=>"cool", "foo"=>"bar"}

Caches data about the CloudFiles::StorageObject for fast retrieval. This method is automatically called when the class is initialized, but it can be called again if the data needs to be updated.

If the parent container is public (CDN-enabled), returns the CDN URL to this object. Otherwise, return nil

  public_object.public_url
  => "http://c0001234.cdn.cloudfiles.rackspacecloud.com/myfile.jpg"

  private_object.public_url
  => nil
refresh()

Alias for populate

A convenience method to stream data from an object into a local file

Throws an Errno::ENOENT if the file cannot be opened for writing due to a path error, and Errno::EACCES if the file cannot be opened for writing due to permissions.

  object.data
  => "This is my data"

  object.save_to_filename("/tmp/file.txt")
  => true

  $ cat /tmp/file.txt
  "This is my data"

  object.save_to_filename("/tmp/owned_by_root.txt")
  => Errno::EACCES: Permission denied - /tmp/owned_by_root.txt

Sets the metadata for an object. By passing a hash as an argument, you can set the metadata for an object. However, setting metadata will overwrite any existing metadata for the object.

Throws NoSuchObjectException if the object doesn‘t exist. Throws InvalidResponseException if the request fails.

Takes supplied data and writes it to the object, saving it. You can supply an optional hash of headers, including Content-Type and ETag, that will be applied to the object.

If you would rather stream the data in chunks, instead of reading it all into memory at once, you can pass an IO object for the data, such as: object.write(open(’/path/to/file.mp3’))

You can compute your own MD5 sum and send it in the "ETag" header. If you provide yours, it will be compared to the MD5 sum on the server side. If they do not match, the server will return a 422 status code and a MisMatchedChecksumException will be raised. If you do not provide an MD5 sum as the ETag, one will be computed on the server side.

Updates the container cache and returns true on success, raises exceptions if stuff breaks.

  object = container.create_object("newfile.txt")

  object.write("This is new data")
  => true

  object.data
  => "This is new data"

If you are passing your data in via STDIN, just do an

  object.write

with no data (or, if you need to pass headers)

 object.write(nil,{'header' => 'value})

[Validate]