I am using the Java Jersey to implement a REST service. One thing my service should provide is a file download option. These files are quite big and are constructed from data from db.
Currently I am fetching all data from the db and saving it to a file and returning a
Response.ok().entity(new FileInputStream(file)).build();
Is there a way how I can start serving the file without fully downloading the data from db, but as the data comes from db append it to the Output stream ?
How about
File fileToSend = getFile();
return Response.ok(fileToSend, "application/zip").build();
The media type can be set to match the file being sent.
This looks pretty straight forward but more importantly, do java experts reading this see a performance problem with the solution?
Solved the problem by using the answer from Input and Output binary streams using JERSEY?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With