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

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?
jersey multipartform-data jax-rs streaming
Purushothaman ramraj
source share