File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes regarding file downloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "regarding file downloading" Watch "regarding file downloading" New topic

regarding file downloading

sathish kannan

Joined: Jul 11, 2002
Posts: 29
i have a problem in downloading a file(image files only) from the server. Actually i am reading the file using FileInputStream and BufferedInputStream and writing using OutputStream.When i click to download it is opening in IE but it is not opening in Netscape. I need to open the file directly and not to prompt for Save as / Open it from current location. For your reference my codes:
OutputStream out = response.getOutputStream();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
response.setHeader("Content-Disposition","attachment;filename="+ fileName);
int buffer = 0;
while((buffer =!=-1)
please advice on the above
Thomas Goorden
Ranch Hand

Joined: Aug 15, 2001
Posts: 39
Have you tried setting the response MIME type directly to an image ( response.setContentType("image/jpeg") or response.setContentType("image/gif") )?
It is typical of IE to do what it thinks is most appropriate for a file type, even if you set some weird MIME type like "application/x-filler".
sathish kannan

Joined: Jul 11, 2002
Posts: 29
Ya i tried with that also. But it promts to Save as/ Open it from current location in IE, not in Netscape. My requirement is, user should not be prompted , instead open in the browser directly.when the user click the download , i am opening a small pop-up window and in that the image should be displayed..
please clarify with my requirement.
Peter Kristensson
Ranch Hand

Joined: Jul 02, 2001
Posts: 118
Have you tried with the correct MIME-type but without the "attatchment" clause.
Just set the Content-type and dont set any disposition.
Might work, not sure
sathish kannan

Joined: Jul 11, 2002
Posts: 29
ya ya thomas
its working fine .
thanks thomas
I agree. Here's the link:
subject: regarding file downloading
It's not a secret anymore!