By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,426 Members | 1,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

Simple file link or button doesnt work

P: n/a
pd
guys,

in my web app, i have a simple download button and a href which points
to a file on my server, when the user clicks on the button or the
link, the file should simply be downloaded to the users machine. now
this file is a postgres backup file with the .backup extension.

now when i use the button, in FF the file download button pops up and
i can save the file, i can also right click the href and go save link
as. and it works fine.

but when i use the button or link in IE, it simply opens up the file
in IE as text and displays a bunch a garbage. now the user needs to be
able to download the file and not view it. also on the href link, when
the right clicks and goes save target as IE automatically adds
the .html extension to the file. now i dont have the .backup extension
in my registered file types.

just to end, my href is, <a href="http://localhost:8080/Backup/
Today.backup">Download</aand the button is,
<input type="button" value="Download" onclick="location.href('http://
localhost:8080/Backup/Today.backup')">

please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.

Jun 1 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lee
pd said:
>please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.
That's not the way browsers are supposed to work. The browser
should display the file that you click on in the window if it
knows how. Only if it doesn't know how (or knows that it isn't
safe to try), should it offer to download the contents. Unless,
of course, the server tells the browser that the file should
take some other action.
--

Jun 1 '07 #2

P: n/a
Lee said the following on 5/31/2007 10:04 PM:
pd said:
>please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.

That's not the way browsers are supposed to work. The browser
should display the file that you click on in the window if it
knows how. Only if it doesn't know how (or knows that it isn't
safe to try), should it offer to download the contents. Unless,
of course, the server tells the browser that the file should
take some other action.
Or, the user has explicitly told the browser how to handle a particular
file. IE and FF both have that setting available to the user.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 1 '07 #3

P: n/a
It's true that browsers have various sets of "default behaviors" for
various mimetypes:

- some known mimetypes will by default be displayed inside the
browser.
- some known mimetypes will by default be downloaded to the desktop.
- when no mime type is sent, and the browser doesn't recognize the
file type, then anything could happen, and i suspect that's what's
happening with your backup file.

You can override the download vs show-in-browser "default behavior",
thru the "content-disposition" http header field:

http://www.ietf.org/rfc/rfc2183.txt

Try configuring your http server so that .backup files will have a
correct mime type if one is defined, but more relevantly, try to make
sure your server sends an additional HTTP Header:

Content-Disposition: attachment; filename=MYFILE.backup

Flickr.com has some good examples of overriding a browser's default
behavior of loading images inside the browser window and forcing a
download thru the Content-Disposition header. If you have a flickr
account, look at a picture's "all sizes" page, and click the
"Download" link. It's a simple HREF Anchor Tag, but the HTTP Response
does set the Content-Disposition header, here's an excerpt from a
response to a click on one of my images:

HTTP/1.0 200 OK
Date: Fri, 01 Jun 2007 08:12:34 GMT
Server: Apache/2.0.52 (Red Hat)
Content-Disposition: attachment;
filename=516875174_4be52f4dbd_b.jpg <---- LOOK RIGHT HERE
Pragma: no-cache
Expires: 0
Last-Modified: Sun, 27 May 2007 23:30:50 GMT
Accept-Ranges: bytes
Content-Length: 396060
Content-Type: image/jpeg <--- ALWAYS A GOOD IDEA TO SET PROPER
MIMETYPE AS Content-Type header value
X-Cache: MISS from photocache3.flickr.mud.yahoo.com

On May 31, 9:55 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Lee said the following on 5/31/2007 10:04 PM:
pd said:
please help me. all i want the user to be able to do is, to download
the file, and they can either go right click and save target or just
click on it and the download dialog should pop up. thanks.
That's not the way browsers are supposed to work. The browser
should display the file that you click on in the window if it
knows how. Only if it doesn't know how (or knows that it isn't
safe to try), should it offer to download the contents. Unless,
of course, the server tells the browser that the file should
take some other action.

Or, the user has explicitly told the browser how to handle a particular
file. IE and FF both have that setting available to the user.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Jun 1 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.