?
Solved

Single-click download jpg (instead of right-clilck -> save as...)

Posted on 2007-08-09
5
Medium Priority
?
457 Views
Last Modified: 2013-12-25
Haven't figured this out...  Gmail gives you two links for attached jpgs - a View and Download link.  The view link works like any link, it opens the jpg in the browser.  The download however asks you to download the file.  How?

Every other site I've seen that wants their visitor to download a jpg puts instructions on the screen to right-click and select "Save as..."  How did Google get the browser to skip those steps?

I've inspected the headers with Fiddler HTTP Debugging Proxy, but it shows the Content-Type and everything else being the same between the view and download links.

I would love to know how they do this.
0
Comment
Question by:eaglewizard_1975
  • 3
5 Comments
 
LVL 6

Expert Comment

by:gjutras
ID: 19663566
The content type is how I do it with pdf's.  I use
application/octet-stream for a type I want to be downloaded
or it's real type if I want the files application to open it naturally.
0
 
LVL 1

Author Comment

by:eaglewizard_1975
ID: 19663583
Yeah, but that doesn't work with jpgs.  The natural action a browser takes it to open a jpg, gif, bmp, etc.  Google's found a way to override that natural action.
0
 
LVL 15

Accepted Solution

by:
StingRaY earned 2000 total points
ID: 19667592
Do not link to the jpg directly, but use server-sided script page instead.
For example, http://www.domain.com/getfile.php?file=yourfile.jpg

In the script, add some additional header before write out the file content.

content-disposition=attachment; filename=yourfile.jpg;

Hope this help.
0
 
LVL 1

Author Comment

by:eaglewizard_1975
ID: 19667658
OK, I'll give it a try.
0
 
LVL 1

Author Comment

by:eaglewizard_1975
ID: 19671830
Since you posted the content-disposition:attachment, I was able to look up some more pertinent info.
http://support.microsoft.com/kb/279667

I also found some code someone already wrote to accomplish this in .NET and in SQL.
http://www.aspnetmime.com/tutorials/Sample_AttachmentToBrowser.aspx
http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question