Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/mindee/http/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def predict_req_post(input_source, opts)
form_data.push ['include_mvision', 'true'] if opts.all_words

req.set_form(form_data, 'multipart/form-data')
req['Transfer-Encoding'] = 'chunked'

Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @request_timeout) do |http|
return http.request(req)
end
Expand Down Expand Up @@ -163,6 +165,7 @@ def document_queue_req_post(input_source, opts)
form_data.push ['include_mvision', 'true'] if opts.all_words

req.set_form(form_data, 'multipart/form-data')
req['Transfer-Encoding'] = 'chunked'

Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @request_timeout) do |http|
return http.request(req)
Expand Down
1 change: 1 addition & 0 deletions lib/mindee/http/workflow_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def workflow_execution_req_post(input_source, opts)
form_data.push ['priority', opts.priority.to_s] if opts.priority

req.set_form(form_data, 'multipart/form-data')
req['Transfer-Encoding'] = 'chunked'

response = nil
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @request_timeout) do |http|
Expand Down
1 change: 1 addition & 0 deletions sig/custom/net_http.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Net
def initialize: (untyped, Hash[String, String]?) -> void
def set_form: (untyped, String?) -> void
def new: (untyped, untyped) -> void
def []=: (?untyped, ?untyped) -> bool
end

# Stub for the HTTP GET request class.
Expand Down
17 changes: 15 additions & 2 deletions spec/input/sources/url_input_source_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'mindee'

describe Mindee::Input::Source::URLInputSource do
let(:client) { Mindee::Client.new(api_key: ENV.fetch('MINDEE_API_KEY')) }

it 'retrieves response from a remote file' do
api_key = ENV.fetch('MINDEE_API_KEY', nil)
client = Mindee::Client.new(api_key: api_key)
remote_input = Mindee::Input::Source::URLInputSource.new('https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/invoice_5p.pdf?raw=true')

local_input = remote_input.as_local_input_source
Expand All @@ -14,4 +14,17 @@
result = client.parse(local_input, Mindee::Product::Invoice::InvoiceV4)
expect(result.document.n_pages).to eq(5)
end

it 'streams with chunked transfer‐encoding without creating temp files' do
remote_input = Mindee::Input::Source::URLInputSource
.new('https://upload.wikimedia.org/wikipedia/commons/1/1d/Blank_Page.pdf')
allow(Tempfile).to receive(:new).and_call_original
allow(Tempfile).to receive(:create).and_call_original

result = client.parse(remote_input, Mindee::Product::Invoice::InvoiceV4)

expect(result.document.n_pages).to eq(1)
expect(Tempfile).not_to have_received(:new)
expect(Tempfile).not_to have_received(:create)
end
end