Merge pull request #330 from joker1007/enable-upload-to-use-tempfile
Add Tempfile to if statement of BaseUploadCommand#prepare!
This commit is contained in:
commit
a0d99ba253
|
@ -82,7 +82,7 @@ module Google
|
||||||
# @raise [Google::Apis::ClientError] if upload source is invalid
|
# @raise [Google::Apis::ClientError] if upload source is invalid
|
||||||
def prepare!
|
def prepare!
|
||||||
super
|
super
|
||||||
if upload_source.is_a?(IO) || upload_source.is_a?(StringIO)
|
if streamable?(upload_source)
|
||||||
self.upload_io = UploadIO.from_io(upload_source, content_type: upload_content_type)
|
self.upload_io = UploadIO.from_io(upload_source, content_type: upload_content_type)
|
||||||
@close_io_on_finish = false
|
@close_io_on_finish = false
|
||||||
elsif upload_source.is_a?(String)
|
elsif upload_source.is_a?(String)
|
||||||
|
@ -97,6 +97,12 @@ module Google
|
||||||
def release!
|
def release!
|
||||||
upload_io.close if @close_io_on_finish
|
upload_io.close if @close_io_on_finish
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def streamable?(upload_source)
|
||||||
|
upload_source.is_a?(IO) || upload_source.is_a?(StringIO) || upload_source.is_a?(Tempfile)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Implementation of the raw upload protocol
|
# Implementation of the raw upload protocol
|
||||||
|
|
|
@ -129,6 +129,20 @@ RSpec.describe Google::Apis::Core::RawUploadCommand do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context('with Tempfile input') do
|
||||||
|
let(:file) do
|
||||||
|
temp_file = Tempfile.new("tempfile")
|
||||||
|
temp_file.write("Hello world\n")
|
||||||
|
temp_file.rewind
|
||||||
|
temp_file
|
||||||
|
end
|
||||||
|
include_examples 'should upload'
|
||||||
|
|
||||||
|
it 'should not close stream' do
|
||||||
|
expect(file.closed?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context('with file path input') do
|
context('with file path input') do
|
||||||
let(:file) { File.join(FIXTURES_DIR, 'files', 'test.txt') }
|
let(:file) { File.join(FIXTURES_DIR, 'files', 'test.txt') }
|
||||||
include_examples 'should upload'
|
include_examples 'should upload'
|
||||||
|
|
Loading…
Reference in New Issue