On Monday 20 Feb 2006 02:41, downloading files wrote:
I tried going to:
and that gives a routing error.
You’ll need to fix that first - perhaps drop off the “.xml”, and go to
… assuming your controller is called “files” and the action is “test”.
as far as setting the “Content-Dispotion” I don’t know how to do that.
I use something like this to export xml as a download from my database:
headers[‘Content-Type’] = “application/xml”
headers[‘Pragma’] = “no-cache”
headers[‘Cache-Control’] = “no-cache, must-revalidate”
headers[‘Expires’] = “0”
filename = Time.now.strftime(“my_xml_download_%Y%m%d_%H%M.xml”)
headers[‘Content-Disposition’] = “attachment; filename=” + filename
@thedata_to_export = Yourmodel.find(:all)
Assuming you want to export a bunch of xml from your model, although it
like you possibly just want to download ready-existing xml files from
public directory, in which case you don’t really need the above… heh,
OK, now I’ve re-read your email (d’oh) - you have existing xml files to
download, and you’ve put them in public/files and you simply want to
them to download, rather than display in the browser.
Not sure how to do this with WEBrick or Lighttpd, but with Apache,
quite a cheap and dirty method you could use, if you really want to
download rather than display in the browser (assuming the browser
displays XML, which most do).
Make a file called “.htaccess” (that’s “dot htaccess”) in your files
directory, and in it put the following line:
I’ve never tried this exact line myself (though have used this directive
other purposes), but I can’t see why it wouldn’t work. Any file placed
that directory will use the (generic binary, so very unspecific) mime
octet-stream, which always results in a download. This will get you
want, but is a bit of a brutal approach.
There’s probably much nicer ways to achieve this with Rails (using the
mimetype and still giving the download), but you’d have to make a
that deals with the files to download, and in that you’d have to set the
content-disposition (as above) to have the files attached.
Perhaps this page will help you (at least with opening the file…
… and then all you’d have to do is spit it out again as your data, as
attachment from the controller action. Shouldn’t be too hard.
Sorry this is a bit of a ramble, I’m hoping somewhere in there is a
for you, though it’s late and I have too much to do, so… back to the
grindstone for me!
Rent-A-Monkey Website Development
PGP Key: http://www.rentamonkey.com/pgpkey.asc