Hi,
I recently implemented a functionality for uploading and downloading files from a file server (SFTP). My app is based on spring framework. The overall functionality is working fine and I can upload and download files from the server. However I'm getting some error messages in my log files. Before I go on to the errors, let me explain just a little bit about how the upload works:
When the user uploads the file, the overall form is not submitted. Rather than submitting the form, I'm calling my own methods to upload the file to the server.
Once the file's uploaded, the file shows up on the current form with a download icon. Now, the user can continue to upload files and go ahead submit the form. OR, they can decide to click on the download icon and download the already uploaded file. (For whatever reason). Now here's where the problem lies. Since the download methods make use of the response object, once the user clicks on the download icon, my response object is used up and the headers/disposition etc. are set.
Now say the user is trying to download the second file, i see the following errors in my log:
"Servlet.service() for
servlet cfg2app threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response"
As far as I understand, essentially, per-request we only get one response object. After that, we need some way to make the client initiate a new response. And the getOutputStream() once called, can not be called again etc.
I know this is possible because any modern webmails (gmail e.g.) they let us upload files, and then download them to see them before we send the email.
So can anyone shed some light as to what can be done to handle this situation. It is not breaking my application, but this is an error and needs to be handled.
Any help is highly appreciated.