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
John Brisbois said:
 
Exactly what I was looking for. Thanks for sharing!
 
posted 401 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Twitter
You should follow me on Twitter here
About Me
I am a 34-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and two daughters. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.
CFinNC - Carolina ColdFusion / Flex / Air Conference - Oct 17-18, 2009