• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Download jpg's from browser

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Alas, poor Yorick, he knew this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic