1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/openstack/requests/storage/put_object.rb
Dmitry Gutov baff59ad3e Fog::Storage::OpenStack::Real#put_object: Document the block parameter
Fog::Storage::Rackspace::Real#put_object: Same
2013-09-24 03:34:43 +03:00

42 lines
1.3 KiB
Ruby

module Fog
module Storage
class OpenStack
class Real
# Create a new object
#
# When passed a block, it will make a chunked request, calling
# the block for chunks until it returns an empty string.
# In this case the data parameter is ignored.
#
# ==== Parameters
# * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
# * object<~String> - Name for object
# * data<~String|File> - data to upload
# * options<~Hash> - config headers for object. Defaults to {}.
# * block<~Proc> - chunker
#
def put_object(container, object, data, options = {}, &block)
if block_given?
params = { :request_block => block }
headers = options
else
data = Fog::Storage.parse_data(data)
headers = data[:headers].merge!(options)
params = { :body => data[:body] }
end
params.merge!(
:expects => 201,
:idempotent => !params[:request_block],
:headers => headers,
:method => 'PUT',
:path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}"
)
request(params)
end
end
end
end
end