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

[openstack|storage] added the ability to upload files using blocks in the same manner as the Rackspace provider

This commit is contained in:
Kyle Rames 2013-07-11 16:19:31 -05:00
parent a23d615ad5
commit 88339d5475
2 changed files with 40 additions and 6 deletions

View file

@ -11,19 +11,22 @@ module Fog
# * data<~String|File> - data to upload
# * 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)
headers = data[:headers].merge!(options)
request(
:body => data[:body],
params = block_given? ? { :request_block => block } : { :body => data[:body] }
params.merge!(
:expects => 201,
:idempotent => true,
:headers => headers,
:method => 'PUT',
:path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}"
)
end
request(params)
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)
end
tests("#get_object('fogobjectests', 'fog_object')").succeeds do
tests("#get_object('fogobjectests', 'fog_object')").returns(lorem_file.read) do
pending if Fog.mocking?
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object')
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object').body
end
tests("#get_object('fogobjecttests', 'fog_object', &block)").returns(lorem_file.read) do
@ -41,6 +41,37 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_object')
end
tests("put_object with block") do
tests("#put_object('fogobjecttests', 'fog_object', &block)") do
pending if Fog.mocking?
begin
file = lorem_file
buffer_size = file.size / 2 # chop it up into two buffers
Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_block_object', nil) do
if file.pos < file.size
file.sysread(buffer_size)
else
""
end
end
ensure
file.close
end
end
tests("object successfully uploaded?").returns(lorem_file.read) do
pending if Fog.mocking?
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_block_object').body
end
tests("delete file").succeeds do
pending if Fog.mocking?
Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_block_object')
end
end
end
tests('failure') do