Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

odd attachment content-dispostion behaviour

Status
Not open for further replies.

bjnst6

Programmer
Aug 10, 2002
5
US
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
 
Which browsers have you tried ? Which OS's ? Which [if windoze] SP's ? Is it a problem with all and any browser/OS combination or just one ?

--------------------------------------------------
Free Database Connection Pooling Software
 
What happens if you try to download a file of that type from another website?

Cheers,

Dian
 
Excellent questions.

I've only tried IE6 with Windows XP. However, this app only has the requirement to be run on IE6 (or higher) so that part is okay.

Now, if I try to download a file of that type from another website (and the source is set up to notify the content-disposition as an attachment), it does indeed work. A "save" will save the file to my local machine, while an "open" will open the content in the browser.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top