| Class | OpenStack::Swift::StorageObject |
| In: |
lib/openstack/swift/storage_object.rb
|
| Parent: | Object |
| container | [R] | |
| metadata | [R] | |
| name | [R] |
create a new Object in a given Container optional headers: {
:metadata=>{key=>value, key1=>value1, ...}
:content_type=>content type of created object
:etag=>MD5 checksum of object data to be compared to that on server side
:cache_control=>cache control header
:manifest=>set manifest header for segmented large object
}
The container parameter must be an OpenStack::Swift::Container object.
Typically you'd create an Object by first getting a Container:
cont = os.container("foo_container")
cont.create_object("my_new_object", {}, "object data")
Builds a new OpenStack::Swift::StorageObject in the specified container. If force_exist is set, the object must exist or a OpenStack::Exception::ItemNotFound will be raised. If not, an "empty" StorageObject will be returned, ready for data via the write method
The container parameter must be an OpenStack::Swift::Container object.
This constructor is typically not called directly. You can get a reference to an existing Object via OpenStack::Swift::Container::object method or create a new Object via OpenStack::Swift::Container::create_object method
Copy this object to a new location (optionally in a new container)
You must supply a name for the new object as well as a container name.
new_object = object.copy("new_obj", "my_container")
You may also supply a hash of headers to set Content-Type, or custom
key=>value metadata:
optional headers: {
:metadata=>{key=>value, key1=>value1, ...}
:content_type=>content type of created object
}
copied = object.copy('newfile.tmp', "my_container", {:content_type=>"text/plain", :metadata=>{:herp=>"derp", "X-Object-Meta-foo"=>"bar} } )
=> => #<OpenStack::Swift::StorageObject:0xb728974c .....
Returns the new OpenStack::Swift::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 OpenStack::Exception::ItemNotFound 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 OpenStack::Exception::ItemNotFound 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.
The method returns the HTTP response object
data = "" object.data_stream do |chunk| data += chunk end => #<Net::HTTPOK 200 OK readbody=true> data => "This is the text stored in the file"
returns just the user defined custom metadata
obj.metadata
=> {"foo"=>"bar, "herpa"=>"derp"}
Takes the same options as the copy method, only it does a copy followed by a delete on the original object.
Returns the new OpenStack::Swift::StorageObject for the moved item. You should not attempt to use the old object after doing a move. optional headers: {
:metadata=>{key=>value, key1=>value1, ...}
:content_type=>content type of created object
}
Retrieves Metadata for the object
object = container.object("conversion_helper.rb")
=> #<OpenStack::Swift::StorageObject:0xb7692488 ....
object.object_metadata
=> {:manifest=>nil, :bytes=>"1918", :content_type=>"application/octet-stream", :metadata=>{"foo"=>"bar, "herpa"=>"derp"}, :etag=>"1e5b089a1d92052bcf759d86465143f8", :last_modified=>"Tue, 17 Apr 2012 08:46:35 GMT", :cache_control=>nil}
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. Returns true if the call was successful. Throws OpenStack::Exception::ItemNotFound if the object doesn‘t exist.
The OpenStack mandated ‘X-Object-Meta’ prefix is optional:
obj.set_metadata({:foo=>"bar", "X-Object-Meta-herpa"=>"derp", "author"=>"me"})
obj.metadata
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.
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"