1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #1958 from rackspace/os_large_files

[openstack|storage] upload files using blocks
This commit is contained in:
Kyle Rames 2013-07-23 11:44:52 -07:00
commit ce3b3936f5
2 changed files with 34 additions and 6 deletions

View file

@ -11,19 +11,22 @@ module Fog
# * data<~String|File> - data to upload # * data<~String|File> - data to upload
# * options<~Hash> - config headers for object. Defaults to {}. # * options<~Hash> - config headers for object. Defaults to {}.
# #
def put_object(container, object, data, options = {}) def put_object(container, object, data, options = {}, &block)
data = Fog::Storage.parse_data(data) data = Fog::Storage.parse_data(data)
headers = data[:headers].merge!(options) headers = data[:headers].merge!(options)
request(
:body => data[:body], params = block_given? ? { :request_block => block } : { :body => data[:body] }
params.merge!(
:expects => 201, :expects => 201,
:idempotent => true, :idempotent => true,
:headers => headers, :headers => headers,
:method => 'PUT', :method => 'PUT',
:path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}"
) )
end
request(params)
end
end end
end end
end end

View file

@ -17,9 +17,9 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', lorem_file) Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', lorem_file)
end end
tests("#get_object('fogobjectests', 'fog_object')").succeeds do tests("#get_object('fogobjectests', 'fog_object')").returns(lorem_file.read) do
pending if Fog.mocking? pending if Fog.mocking?
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object') Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object').body
end end
tests("#get_object('fogobjecttests', 'fog_object', &block)").returns(lorem_file.read) do tests("#get_object('fogobjecttests', 'fog_object', &block)").returns(lorem_file.read) do
@ -41,6 +41,31 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_object') Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_object')
end end
tests("put_object with block") do
pending if Fog.mocking?
tests("#put_object('fogobjecttests', 'fog_object', &block)").succeeds do
begin
file = lorem_file
buffer_size = file.stat.size / 2 # chop it up into two buffers
Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_block_object', nil) do
file.read(buffer_size).to_s
end
ensure
file.close
end
end
tests('#get_object').succeeds do
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_block_object').body == lorem_file.read
end
tests('#delete_object').succeeds do
Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_block_object')
end
end
end end
tests('failure') do tests('failure') do