2013-01-23 14:26:17 -05:00
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class OpenStack
|
|
|
|
class Real
|
|
|
|
|
|
|
|
# Create a new object
|
|
|
|
#
|
2013-09-23 20:21:58 -04:00
|
|
|
# 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.
|
|
|
|
#
|
2013-01-23 14:26:17 -05:00
|
|
|
# ==== 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 {}.
|
2013-09-23 20:21:58 -04:00
|
|
|
# * block<~Proc> - chunker
|
2013-01-23 14:26:17 -05:00
|
|
|
#
|
2013-07-11 17:19:31 -04:00
|
|
|
def put_object(container, object, data, options = {}, &block)
|
2013-09-22 00:07:08 -04:00
|
|
|
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
|
2013-07-11 17:19:31 -04:00
|
|
|
|
|
|
|
params.merge!(
|
2013-01-23 14:26:17 -05:00
|
|
|
:expects => 201,
|
2013-07-27 19:07:04 -04:00
|
|
|
:idempotent => !params[:request_block],
|
2013-01-23 14:26:17 -05:00
|
|
|
:headers => headers,
|
|
|
|
:method => 'PUT',
|
|
|
|
:path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}"
|
|
|
|
)
|
|
|
|
|
2013-07-11 17:19:31 -04:00
|
|
|
request(params)
|
|
|
|
end
|
2013-01-23 14:26:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|