aspose file tools*
The moose likes Servlets and the fly likes Download jpg's from browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Download jpg Watch "Download jpg New topic
Author

Download jpg's from browser

Jason Brawner
Ranch Hand

Joined: Dec 19, 2001
Posts: 66
Our website contains many photos that users can retrieve. Currently they have to click on the thumbnail of their photo which opens a new browser window with their photo at full scale. Then they have to right-click -> Save as... to download.

Is it possible to tell the browser not to open the photo in the new window, but to prompt the open/save dialog when they click on the thumbnail? I'd like to do this without giving the file a wierd extension or zipping it. Is there an http header to set or am I out of luck?

Thanks,

Jason


Jason E. Brawner<br />Sun Certified Java Programmer<br />Sun Certified Web Component Developer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

When the user clicks on the thumbnail, submit to a servlet that returns the full-size image as a byte stream with the appropriate content type set onto the response.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jason Brawner
Ranch Hand

Joined: Dec 19, 2001
Posts: 66
...but if I provide the appropriate content type (image/jpeg) won't the browser recognize it and display the photo rather than prompt for download? And if it did work, the user would be presented with a weird default file name (probably the servlet mapping) in the 'Save as' dialog. They'd have to be instucted to put a .jpg ext on the file before they saved it to their hard drive... too confusing for the average user.

Regardless, I will try it tomorrow.

Thanks
Peter Bell
Greenhorn

Joined: Mar 25, 2003
Posts: 19
You could always change the content type to something other than "image/...".

Alternatively: consider that most users don't expect clicking on images to download them. They expect to see them. And a good number of them would know what to do to save the image if they needed to.


RimuHosting - JSP and Java Hosting
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
refreshing change from the constant questions on how to PREVENT people from saving images displayed in their browsers

A good way that works is to serve the image in a format that browsers can't display.
BMP and TIFF are good examples (though there's no guarantee that there are no browsers at all that can't show them of course).


42
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Also set the 'content disposition' so that the browser knows that the response is a file (you can even name it) attachment. Search for 'content-disposition' for examples.
Jason Brawner
Ranch Hand

Joined: Dec 19, 2001
Posts: 66
thanks for the ideas.... the only reason I need to investigate this approach is because a client wants their site to work this way, even though it is a bit silly.

Thanks,

Jason
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download jpg's from browser