5

I am writing a REST API in JAX-RS 2.0, JDK 8 for the below requirement

POST API /server/fileUpload/ (Multipart Form data) where I need to send a Big .AI (Adobe Illustrator) File in this.

The Server, takes the file and return Status 202 (Accepted), Acknowledging that file transfer happened Successfully. (From endpoint to Server)

Now at the Server, I am using Java + Imagemagik to convert .AI File (20-25 MB File) to small JPG Thumbnail, place on a Apache HTTP Server and share the location (like http://happyplace/thumbnail0987.jpg)

Now the Second Response should come from Server with Status 200 OK and Thumbnail URL

is it feasible with one REST API? (Async/similar)

or should I split it to 2 API calls, Please suggest

Sandeep540
  • 897
  • 3
  • 13
  • 38
  • 1
    Possible duplicate of [HTTP Status 202 - how to provide information about async request completion?](https://stackoverflow.com/questions/14832983/http-status-202-how-to-provide-information-about-async-request-completion) – Aleh Maksimovich Oct 14 '17 at 18:36

7 Answers7

3

No. In http, one request gets one response. The client must send a second request to get a second response.

DwB
  • 37,124
  • 11
  • 56
  • 82
1

The best way to handle these kind of scenario is to use Java Reactive (Project Reactor, WebFlux).

Naveen Jain
  • 1,042
  • 7
  • 26
1

As told by @Naveen , it should be stream and response should be

Content-Type: text/event-stream

enter image description here

and the response should be Async stream of events

Sandeep540
  • 897
  • 3
  • 13
  • 38
0

If you are calling from script the call will be async you can handle the Thumbnail URL when you get a response. When you are calling from java program i suggest to run it on a different thread, If the execution is not sequential i.e ( Remaining lines can be executed without getting URL). If url is needed for the remaining section of code you can make one call and wait for the response then execute remaining code.

0

You need to make different APIs for both scenarios. One for showing file upload status and another for all file conversion and manipulation.

On the client side second request must be callback of first request.

0

You can use WebSockets for that.

  • 10
    Please make this a proper answer. One sentence with no citation, proof, links, code, expansions or anything really do not make for a very good answer. Please explain why he must use WebSockets. – Uberhumus Jun 05 '20 at 21:00
0

You can return two response using custom middlewares in asp.net (however not recommended).

Return response from one middleware and subsequently you can invoke next middleware and return second response from second middleware