I want to write an simple java servlet which receives file upload from a simple html page, does something with the file and sends back the manipulated file to the user.
The file upload event is handled by doPost method of a servlet on the server side. The requirements is that "Save as..." window needs to be appear immediately after the file is uploaded and processed on the server side and user can save the generated file to his/her computer.
File upload is handled by doPost and file download is handled by doGet method of a servlet. Is it possible to boundle these two events together somehow?
Can I receive byte content as a response of a file upload event? I upload file with ajax post and I can send back content to the browser and I can show this message on the client side.
Is it possible to write a clever java script code which receives binary content as a response of a post request and forces the web browser to pop up the "save as..." window for save the received bytes to a file?
Another solution could be
- file upload with ajax
- on the server side the new generated content is saved to a file into a temporary directory
- id or path of the file on the server is sent back to the client as a response
- client (java script) receives the id of the generated file and makes a new GET request immediately to a file download servlet
- file download servlet receives the id/path of the file and reads it from the temp folder and send i bact to the client web browser.
What is the best practice for this scenario?