Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at the New York ColdFusion User Group (Jul. 2008) with: Simon Free and Peter Bell and Dan Wilson
Ben Nadel at the New York ColdFusion User Group (Jul. 2008) with: Simon Free@simonfree ) , Peter Bell@peterbell ) , and Dan Wilson@DanWilson )

Use A GetTempFile() Prefix That Links The File Back To The Code That Created It

By Ben Nadel on
Tags: ColdFusion

When you use the getTempFile() function, in ColdFusion, you can provide a prefix that will be used in the generated filename. According to the ColdFusion documentation, only 3-characters of this prefix value will be used. However, this is often misleading. I suggest using a prefix that contains information sufficient to link the file back to the code that created it.

I've developed ColdFusion applications on both Windows and *nix machines and I've never seen ColdFusion actually truncate a prefix that I've given to the getTempFile() function. As such, I've developed a habit of creating long [enough] prefix values that clearly indicate what portion of the code-base created the temporary file.

When we run this code:

  • <cfscript>
  •  
  • // Explore the use of long getTempFile() prefix values.
  • getTempFile( getTempDirectory(), "bn-processing-asset-id-4-" );
  • getTempFile( getTempDirectory(), "bn-importing-excel-document-16-" );
  • getTempFile( getTempDirectory(), "bn-exporting-monthly-report-91470342014081-csv-" );
  •  
  • </cfscript>

... we create the following temporary files (on my local Mac):


 
 
 

 
 getTempFile() function in ColdFusion can use a long prefix. 
 
 
 

As you can see, none of the prefix values were truncated - not even the one that contains 47 characters.

Personally, I'm not a huge fan of the getTempFile() function. Most of the time, I create a UUID (Universally Unique Identifier)-based scratch directory in which uniqueness is no longer a concern. But, if and when I do use the getTempFile() function, I always make sure to use a prefix that clearly indicates from where in the code-base it originated.




Reader Comments

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.