Class | CloudFiles::StorageObject |
In: |
lib/cloudfiles/storage_object.rb
|
Parent: | Object |
container | [R] | The parent CloudFiles::Container object |
name | [R] | Name of the object corresponding to the instantiated object |
Builds a new CloudFiles::StorageObject in the current container. If force_exist is set, the object must exist or a CloudFiles::Exception::NoSuchObject Exception will be raised. If not, an "empty" CloudFiles::StorageObject will be returned, ready for data via CloudFiles::StorageObject.write
Copy this object to a new location (optionally in a new container)
You must supply either a name for the new object or a container name, or both. If a :name is supplied without a :container, the object is copied within the current container. If the :container is specified with no :name, then the object is copied to the new container with its current name.
object.copy(:name => "images/funny/lolcat.jpg", :container => "pictures")
You may also supply a hash of headers in the :headers option. From there, you can set things like Content-Type, or other headers as available in the API document.
object.copy(:name => 'newfile.tmp', :headers => {'Content-Type' => 'text/plain'})
Returns the new CloudFiles::StorageObject for the copied item.
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)
You can provide an optional hash of headers, in case you want to do something like set the Content-Type manually.
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.load_from_filename("/home/rackspace/myfile.tmp", 'Content-Type' => 'text/plain') 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"}
Takes the same options as the copy method, only it does a copy followed by a delete on the original object.
Returns the new CloudFiles::StorageObject for the moved item. You should not attempt to use the old object after doing a move.
If the parent container is public (CDN-enabled), returns the SSL CDN URL to this object. Otherwise, return nil
public_object.public_ssl_url => "https://c61.ssl.cf0.rackcdn.com/myfile.jpg" private_object.public_ssl_url => nil
If the parent container is public (CDN-enabled), returns the SSL CDN URL to this object. Otherwise, return nil
public_object.public_streaming_url => "https://c61.stream.rackcdn.com/myfile.jpg" private_object.public_streaming_url => nil
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
Purges CDN Edge Cache for all objects inside of this container
:email, An valid email address or comma seperated list of emails to be notified once purge is complete .
obj.purge_from_cdn => true or obj.purge_from_cdn("User@domain.com") => true or obj.purge_from_cdn("User@domain.com, User2@domain.com") => true
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
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 CloudFiles::Exception::MisMatchedChecksum Exception 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})