• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Download jpg's from browser

 
Jason Brawner
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jason Brawner
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic