aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "regarding file downloading" Watch "regarding file downloading" New topic
Author

regarding file downloading

sathish kannan
Greenhorn

Joined: Jul 11, 2002
Posts: 29
Hi
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.setContentType("application/x-filler");
response.setHeader("Content-Disposition","attachment;filename="+ fileName);
int buffer = 0;
while((buffer = bis.read())!=-1)
{
out.write(buffer);
}
out.flush();
out.close();
bis.close();
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
Greenhorn

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.
thanks
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
/Peter
sathish kannan
Greenhorn

Joined: Jul 11, 2002
Posts: 29
ya ya thomas
its working fine .
thanks thomas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding file downloading
 
Similar Threads
Opening a PDF
error locating file in servlet
A problem with servlet file transfer
download link in jsp ?
Adding files to existing zip archive