Method: OpenStack::Swift::StorageObject#write
- Defined in:
- lib/openstack/swift/storage_object.rb
#write(data, headers = {}) ⇒ Object
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"
245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/openstack/swift/storage_object.rb', line 245 def write(data, headers = {}) server = @container.swift.connection.service_host path = @container.swift.connection.service_path + URI.encode("/#{@containername}/#{@name}") port = @container.swift.connection.service_port scheme = @container.swift.connection.service_scheme body = (data.is_a?(String))? StringIO.new(data) : data body.binmode if (body.respond_to?(:binmode)) response = @container.swift.connection.put_object(server, path, port, scheme, headers, body, 0) raise OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |