Hello everyone,
I've inherited a web application that needs some tweaking. Right now the app has a feature to upload files of any type (which works fine), store them in an Oracle 8i db, and then have the user download them at another time. The downloading is where the problem occurs. I'm using the code snippet below:
out = new BufferedOutputStream(response.getOutputStream());
response.setContentType(fileBean.getContentType());
response.setHeader("Content-Disposition", "attachment; filename=" + fileBean.getName());
out.write(fileBean.getData());
out.flush();
When the user clicks on the button download a file with the above code in place, it prompts him with a choice to "save", "open", or "cancel". This is perfect. The "save" and "cancel" options work wonderfully. However, the "open" option doesn't work for any type of file. It gives a different message for each file type, but the just of it is that it can't find the file specified. This seems very odd to me because it can save the file just fine.
Also, I tried changing the content-disposition to "inline" instead of "attachment" which does indeed work as well. All of the different file types open up in the browser just like they should, the only problem here is that I need a prompt from to appear for the user to make that choice like he has if "attachment" is used. With "inline" there is no choice, it just (obviously) opens it up inline every time.
However, this does lead me to believe that I'm setting the content-type correctly, so that's a plus. The FileBean above does indeed return the correct content-type that was stored in the db when the file was uploaded.
Does anyone have any idea how to get the "open" option to work for the "attachment" option?
Many, many thanks!
bryan
I've inherited a web application that needs some tweaking. Right now the app has a feature to upload files of any type (which works fine), store them in an Oracle 8i db, and then have the user download them at another time. The downloading is where the problem occurs. I'm using the code snippet below:
out = new BufferedOutputStream(response.getOutputStream());
response.setContentType(fileBean.getContentType());
response.setHeader("Content-Disposition", "attachment; filename=" + fileBean.getName());
out.write(fileBean.getData());
out.flush();
When the user clicks on the button download a file with the above code in place, it prompts him with a choice to "save", "open", or "cancel". This is perfect. The "save" and "cancel" options work wonderfully. However, the "open" option doesn't work for any type of file. It gives a different message for each file type, but the just of it is that it can't find the file specified. This seems very odd to me because it can save the file just fine.
Also, I tried changing the content-disposition to "inline" instead of "attachment" which does indeed work as well. All of the different file types open up in the browser just like they should, the only problem here is that I need a prompt from to appear for the user to make that choice like he has if "attachment" is used. With "inline" there is no choice, it just (obviously) opens it up inline every time.
However, this does lead me to believe that I'm setting the content-type correctly, so that's a plus. The FileBean above does indeed return the correct content-type that was stored in the db when the file was uploaded.
Does anyone have any idea how to get the "open" option to work for the "attachment" option?
Many, many thanks!
bryan