0

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

ColdFusion

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.

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.

tags:
ColdFusion

Search

About Me
I am a 32-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and daughter. I work for Interfolio where we help people collect, deliver and showcase their life's work. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.