Sam Farmer

Growing up I never imagined I would play bass guitar for the Dave Matthews Band. And indeed it never happened.

But I have become passionate about making software.

Tip: Using the getTempDirectory Function for Temp Files Intended for Download

April 19, 2007

So one issue I ran into with Ben Nadel's POIUtility is that, in its current form, you can not return the Excel file directly to the browser but instead need to save it to disk and then return it. No big deal really and here is what I did to avoid collecting files on the server.

[codeshare apr95c94]

By using the getTempDirectory function of ColdFusion I do not need to worry about setting up a folder for these files or getting the correct path in all environments. Then I use the createUUID function to get a unique file name, I could have also used getTempFile, but I use createUUID a lot so its just a personal preference.

The cfheader call tells the browser that the new file is to be called FileName.xls and not index.cfm or whatever page I am on. I then use cfcontent to a) set the mime-type to excel, b) delete the file when the download has completed and c) to state which file to download.


No Comments

Some comments have been lost over the years due to moving hosts.

More


More blog entries that I have written.

Code coloring by PRISM.