55import com .mindee .MindeeException ;
66import com .mindee .MindeeSettingsV2 ;
77import com .mindee .input .LocalInputSource ;
8+ import com .mindee .input .URLInputSource ;
89import com .mindee .parsing .v2 .CommonResponse ;
910import com .mindee .parsing .v2 .ErrorResponse ;
1011import com .mindee .parsing .v2 .InferenceResponse ;
@@ -79,8 +80,52 @@ public JobResponse reqPostInferenceEnqueue(
7980 InferenceParameters options
8081 ) {
8182 String url = this .mindeeSettings .getBaseUrl () + "/inferences/enqueue" ;
82- HttpPost post = buildHttpPost (url , inputSource , options );
83+ HttpPost post = buildHttpPost (url , options );
8384
85+ MultipartEntityBuilder builder = MultipartEntityBuilder .create ();
86+ builder .setMode (HttpMultipartMode .EXTENDED );
87+ builder .addBinaryBody (
88+ "file" ,
89+ inputSource .getFile (),
90+ ContentType .DEFAULT_BINARY ,
91+ inputSource .getFilename ()
92+ );
93+ post .setEntity (buildHttpBody (builder , options ));
94+ return executeEnqueue (post );
95+ }
96+
97+
98+ /**
99+ * Enqueues a doc with the POST method.
100+ *
101+ * @param inputSource Input source to send.
102+ * @param options Options to send the file along with.
103+ * @return A job response.
104+ */
105+ @ Override
106+ public JobResponse reqPostInferenceEnqueue (
107+ URLInputSource inputSource ,
108+ InferenceParameters options
109+ ) {
110+ String url = this .mindeeSettings .getBaseUrl () + "/inferences/enqueue" ;
111+ HttpPost post = buildHttpPost (url , options );
112+
113+ MultipartEntityBuilder builder = MultipartEntityBuilder .create ();
114+ builder .setMode (HttpMultipartMode .EXTENDED );
115+ builder .addTextBody (
116+ "url" ,
117+ inputSource .getUrl ()
118+ );
119+ post .setEntity (buildHttpBody (builder , options ));
120+ return executeEnqueue (post );
121+ }
122+
123+ /**
124+ * Executes an enqueue action, common to URL & local inputs.
125+ * @param post HTTP Post object.
126+ * @return a valid job response.
127+ */
128+ private JobResponse executeEnqueue (HttpPost post ) {
84129 mapper .findAndRegisterModules ();
85130 try (CloseableHttpClient httpClient = httpClientBuilder .build ()) {
86131 return httpClient .execute (
@@ -146,9 +191,9 @@ public JobResponse reqGetJob(
146191 }
147192
148193 @ Override
149- public InferenceResponse reqGetInference (String jobId ) {
194+ public InferenceResponse reqGetInference (String inferenceId ) {
150195
151- String url = this .mindeeSettings .getBaseUrl () + "/inferences/" + jobId ;
196+ String url = this .mindeeSettings .getBaseUrl () + "/inferences/" + inferenceId ;
152197 HttpGet get = new HttpGet (url );
153198
154199 if (this .mindeeSettings .getApiKey ().isPresent ()) {
@@ -202,17 +247,9 @@ private MindeeHttpExceptionV2 getHttpError(ClassicHttpResponse response) {
202247
203248
204249 private HttpEntity buildHttpBody (
205- LocalInputSource inputSource ,
250+ MultipartEntityBuilder builder ,
206251 InferenceParameters options
207252 ) {
208- MultipartEntityBuilder builder = MultipartEntityBuilder .create ();
209- builder .setMode (HttpMultipartMode .EXTENDED );
210- builder .addBinaryBody (
211- "file" ,
212- inputSource .getFile (),
213- ContentType .DEFAULT_BINARY ,
214- inputSource .getFilename ()
215- );
216253
217254 if (options .getAlias () != null ) {
218255 builder .addTextBody (
@@ -237,7 +274,6 @@ private HttpEntity buildHttpBody(
237274
238275 private HttpPost buildHttpPost (
239276 String url ,
240- LocalInputSource inputSource ,
241277 InferenceParameters options
242278 ) {
243279 HttpPost post ;
@@ -255,7 +291,6 @@ private HttpPost buildHttpPost(
255291 post .setHeader (HttpHeaders .AUTHORIZATION , this .mindeeSettings .getApiKey ().get ());
256292 }
257293 post .setHeader (HttpHeaders .USER_AGENT , getUserAgent ());
258- post .setEntity (buildHttpBody (inputSource , options ));
259294 return post ;
260295 }
261296
0 commit comments