Start processing the file as soon as it is transferred to Jersey Mulipart

I have a JAX-RS web service that implements a multi-page file download request. The web service needs to compress the file and save it. It takes a lot of time. This processing begins only after the entire file has been downloaded from the client.

I would like to start processing the InputStream file as and when the file becomes available on the server.

My JAX-RS code is:

/** * POST method for uploading a file * @param content representation for the resource * @return an HTTP response with content of the updated or created resource. */ @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public String uploadPhoto ( @FormDataParam("file") final InputStream uploadedInputStream, @FormDataParam("file") final FormDataContentDisposition fileDetail, @FormDataParam("key") final String key, @FormDataParam("userid") final int userId) throws Exception { String imgURL = **FileProcessor.process**(uploadedInputStream); return buildUploadResponse(url); } 

This is a screenshot of how the chrome request time

enter image description here

In the image above, you can see that there are two periods of time "RequestTime" "Timeout". "FileProcess.process" only starts while waiting. Why can't it be executed as soon as the file stream becomes available?

+8
jersey multipartform-data jax-rs streaming
source share

No one has answered this question yet.

See related questions:

one hundred
Input and output binary streams using JERSEY?
4
Stream of big answers with knit, asynchronously
3
InputStream shuts down unexpectedly when using MultiSmart file upload and Server-Sent events (SSE)
2
Manage file loading and buffering using the Jersey API
one
upload org.glassfish.jersey using FormDataContentDisposition
one
Jersey File Upload: Cannot save file in web project
one
Uploading a file using jersey does not work

All Articles