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:
commit
ce3b3936f5
2 changed files with 34 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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,31 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
|
|||
Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_object')
|
||||
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
|
||||
|
||||
tests('failure') do
|
||||
|
|
Loading…
Reference in a new issue