<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Blog of Shaun McCran - Architecting robust, elegant technical and business solutions - File Interactions</title>
			<link>http://www.mccran.co.uk/index.cfm</link>
			<description>I write about Architecture and Design, Architectural patterns, Architectural Principles and Architectural policies. This includes TOGAF, Zachman, Business Architecture, SOA and Process and tools such as the IBM Rational software and Adobe products. I also write about my previous life as a mobile and web developer.</description>
			<language>en-gb</language>
			<pubDate>Tue, 09 Jun 2026 06:50:25 -0000</pubDate>
			<lastBuildDate>Wed, 11 May 2011 12:24:00 -0000</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>shaun@mccran.co.uk</managingEditor>
			<webMaster>shaun@mccran.co.uk</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>shaun@mccran.co.uk</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>Handling CFfile upload &apos;accept&apos; file type errors</title>
				<link>http://www.mccran.co.uk/index.cfm/2011/5/11/Handling-CFfile-upload-accept-file-type-errors</link>
				<description>
				
				&lt;p&gt;
I was working on a system recently that allowed a user to upload images onto the server. It was restricted to files types of images, more specifically &apos;jpeg&apos; and &apos;gif&apos; files.
&lt;p&gt;
This is easily done with the &apos;accept&apos; parameter, as documented in the ColdFusion documentation:
&lt;p&gt;
&lt;code&gt;
Accept:

Limits the MIME types to accept. Comma-delimited list. For example, the following code permits JPEG and Microsoft Word file uploads: 
accept = &quot;image/jpg, application/msword&quot;

The browser uses the file extension to determine file type.

&lt;/code&gt;
&lt;p&gt;
It is important to note here that it is the browser uses the file extension, so renaming an exe to jpg would fool it entirely.
&lt;p&gt;
Issues arise when you don&apos;t handle an invalid file upload in a friendly manner. In this case when a user tried to upload an incorrect file type they saw a nasty unformatted error message stating that the request could not be processed as the file was the wrong Mime type.
&lt;p&gt;
You cannot tell what the file type is until you attempt to upload it, so wrap your cffile tags in a simple try-catch and handle any errors in the same fashion as you normally would, I.E. by handling the system message and instead displaying a nice, user friendly message that doesn&apos;t sound like it was written by robots.
&lt;p&gt;
&lt;code&gt;

&lt;cftry&gt;

&lt;cffile action=&quot;upload&quot; destination=&quot;#request.uploadPath#&quot; fileField=&quot;form.new_image&quot; accept=&quot;image/jpeg, image/gif&quot; nameConflict=&quot;overwrite&quot;&gt;

&lt;cfcatch&gt;

	&lt;cfset attributes.errors.type = &apos;error&apos;&gt;
	&lt;cfset attributes.errors.message = &quot;The type of file you have tried to upload is not allowed, please select a jpg or gif.&quot;&gt;
	&lt;cfset request.continue = false&gt;

&lt;/cfcatch&gt;

&lt;/cftry&gt;

&lt;/code&gt;
&lt;p&gt;
				
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>Best practices</category>
				
				<category>File Interactions</category>
				
				<pubDate>Wed, 11 May 2011 12:24:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2011/5/11/Handling-CFfile-upload-accept-file-type-errors</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>ImageCFC losing file permissions on image manipulation</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/5/7/ImageCFC-loosing-file-permissions-on-image-manipulation</link>
				<description>
				
				This article deals with a work around for a problem I had been experiencing with the imageCFC (&lt;a href=http://www.opensourcecf.com/imagecfc/ target=_blank&gt; http://www.opensourcecf.com/imagecfc/ &lt;/a&gt;) open source project. When resizing an image the file permissions were being lost on the edited file. This meant that the server operating system could not read or serve up the file to the browser.

I&apos;ve been using imageCFC as I have a variety of coldfusion server versions (7 and 8), and I like the fact that in the resize method you can specify the maximum size for the width and height, and it will resize down to that size, and keep the aspect ratio of width-to-height.
				 [More]
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>File Interactions</category>
				
				<pubDate>Fri, 07 May 2010 16:55:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/5/7/ImageCFC-loosing-file-permissions-on-image-manipulation</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Issues dealing with large text files? Use a file splitter App!</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/11/6/Issues-dealing-with-large-text-files-Use-a-file-splitter-App</link>
				<description>
				
				I&apos;ve been dealing with bulk data recently, CSV files of around 500mb or more. These can seriously stress out your pc. In the process of trying to write data import scripts I found an application that has proven its worth a few times over. This application allows you to split text files at points of your choosing.

File Splitter Pro, from wonderwebware. It doesn&apos;t look amazing, and it has a relatively simple interface, but after going through three or four alternatives that for the most part couldn&apos;t even open a 500mb csv file this has come through every time. What I really like though is the function that allows you to select N number of lines and move them to another file.

There is a trial version available too:

&lt;a href=&quot;http://wonderwebware.com/file-splitter-pro/&quot; target=&quot;new&quot;&gt;http://wonderwebware.com/file-splitter-pro/&lt;/a&gt;

(P.S I don&apos;t get commission or anything.)
				
				</description>
				
				
				<category>Recommended Apps</category>
				
				<category>File Interactions</category>
				
				<pubDate>Fri, 06 Nov 2009 14:29:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/11/6/Issues-dealing-with-large-text-files-Use-a-file-splitter-App</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Uploading an image and previewing the thumbnail in one hit</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/10/14/Uploading-an-image-and-previewing-the-thumbnail-in-one-hit</link>
				<description>
				
				A recent piece of functionality required a user to be able to upload an image, and view a thumbnail of that image alongside all the other related details that they were entering (item specific data etc).

After having a look through several forums it seemed that people&apos;s opinions were split on whether this could be accomplished using Ajax at all. So I decided to go old school and use an iFrame. I&apos;m not a big fan of frames in any incarnation, but in this case I was willing to make an exception.

So firstly there is an upload form. It is a pretty standard ColdFusion form. Just remember when uploading a file to set the enctype=&quot;multipart/form-data&quot;. Also the submit button does not submit the form, it fires a JavaScript function &apos;changeFrame()&apos;. The JavaScript function sets the target of the form submission to the iFrame, and then submits it.

&lt;code&gt;
&lt;div&gt;
	&lt;iframe id=&quot;uploadFrame&quot; name=&quot;uploadFrame&quot; src=&quot;action.cfm&quot; height=&quot;110&quot; width=&quot;90&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;
	
&lt;form name=&quot;uploader&quot; action=&quot;action.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
		&lt;input type=&quot;file&quot; name=&quot;image&quot; size=&quot;5&quot;&gt;
		&lt;input type=&quot;button&quot; name=&quot;action&quot; value=&quot;Upload&quot; onclick=&quot;changeFrame()&quot;/&gt;
	&lt;/form&gt;
&lt;/div&gt;

&lt;s/cript&gt;
function changeFrame()
	{
		document.getElementById(&apos;uploader&apos;).target = &apos;uploadFrame&apos;;
		document.getElementById(&apos;uploader&apos;).submit();
	}
&lt;/s/cript&gt;
&lt;/code&gt;

The form submits to the &apos;action.cfm&apos; template. This template displays a placeholder image thumbnail initially, but when the form is submitted it performs the file upload using cffile, then displays the newly uploaded file instead of the placeholder. Ideally at this point I would like to resize the image with cfimage, but my hosting company is still using ColdFusion 7, so I may have to use a third party tag to do the same.

&lt;code&gt;
&lt;body style=&quot;margin: 0;&quot;&gt;
&lt;cfset dest = &quot;webroot/root/tmp/&quot;&gt;

&lt;cfif isdefined(&apos;form.image&apos;)&gt;
	&lt;cffile action=&quot;upload&quot; filefield=&quot;form.image&quot; destination=&quot;#dest#&quot; nameconflict=&quot;makeunique&quot;&gt;
	&lt;cfset variables.img = cffile.clientFile&gt;
&lt;cfelse&gt;
	&lt;cfset variables.img = &quot;holder.gif&quot;&gt;
	
&lt;/cfif&gt;

&lt;cfoutput&gt;&lt;img src=&quot;tmp\#variables.img#&quot; height=&quot;100&quot; width=&quot;75&quot; border=&quot;1&quot;&gt;&lt;/cfoutput&gt;
&lt;/body&gt;
&lt;/code&gt;

It is a shame I had to use an iFrame, and it would be really interesting to see if this is possible in a more web 2.0 scripted way.

&lt;img src=&quot;http://www.mccran.co.uk/images/uploadform.gif&quot; /&gt;
				
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>Javascript</category>
				
				<category>File Interactions</category>
				
				<pubDate>Wed, 14 Oct 2009 13:20:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/10/14/Uploading-an-image-and-previewing-the-thumbnail-in-one-hit</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Introducing third party applications into your frameworks, good practice?</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/10/1/Introducing-third-party-applications-into-your-frameworks-good-practice</link>
				<description>
				
				A recent development involved some changes to a large script that was using a product called ImageMagick (&lt;a href=www.imagemagick.org/ target=&quot;new&quot;&gt;link&lt;/a&gt;). It is an image manipulation tool that allows you to perform transformations and other actions on image files. The product seems stable enough, and can be executed from a web interface using cfexecute, in a kind of command line prompt method.

It got me thinking as to why the application wasn&apos;t using cfimage, and then lead me to examine the wider topic of whether to use ColdFusion&apos;s in built functionality, or opt for other third party products.

I can think of a few obvious deciding factors for both pro and con, the first that springs to mind is performance. 

Is there a marked performance difference between a ColdFusion function, and the third party application? Is it better to pass the load of to the operating system, rather than have ColdFusion perform whatever processing function it is supposed to do? In this case it would be a race between cfexecute, and cfimage, so there may be very little difference in it.

The second major point that springs to mind is the knowledge base of the developer, and the structure of whatever framework you are using. What I really mean by this is &apos;if your chosen technology can perform a function, why not utilise it to its full potential?&apos; . It seems a bizarre choice indeed to deliberately not harness a function that your platform can already provide, and instead introduce another code base or application into the framework. 

It also introduces another hurdle for the development staff, they may well be familiar with how an existing Tag works, but be totally unaware of the third party application, as was my case here.

A long winded intro, but here is the code I used:

&lt;code&gt;
&lt;!--- setup vars ---&gt;
&lt;cfset variables.destination = &quot;C:\dev\images\testimage.jpg&quot;&gt;
&lt;cfset variables.source = &quot;C:\dev\images\testimage.jpg&quot;&gt;
&lt;cfset variables.width = &quot;100&quot;&gt;
&lt;cfset variables.height = &quot;100&quot;&gt;
&lt;cfset variables.exec = &quot;C:\dev\apps\imageMagick\convert.exe&quot;&gt;

&lt;!--- executing an external application version ---&gt;
&lt;cfexecute name=&quot;#variables.exec#&quot; arguments=&quot;-size #variables.width# #variables.source# -geometry #variables.height# -strip #variables.destination#&quot; variable=&quot;imageinfo&quot; timeout=&quot;3&quot; /&gt;

&lt;!--- CFimage version ---&gt;
&lt;cfimage source=&quot;#variables.source#&quot; action=&quot;resize&quot; width=&quot;#variables.width#&quot; height=&quot;#variables.height#&quot; destination=&quot;#variables.destination#&quot;&gt;
&lt;/code&gt;
				
				</description>
				
				
				<category>Software Architecture</category>
				
				<category>Coldfusion</category>
				
				<category>Recommended Apps</category>
				
				<category>Best practices</category>
				
				<category>File Interactions</category>
				
				<pubDate>Thu, 01 Oct 2009 13:18:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/10/1/Introducing-third-party-applications-into-your-frameworks-good-practice</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Incorrect error message reporting using CFFile action rename</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/9/1/Incorrect-error-message-reporting-using-CFFile-action-rename</link>
				<description>
				
				During a batch process that I was writing recently I was using a CFfile operation to rename some files. 

When running it I came across this error message:

&lt;code&gt;
Attribute validation error for tag CFFILE.
The value of the attribute source, which is currently &quot;C:\fullUrl.jpg&quot;, is invalid.
&lt;/code&gt;

This is the calling cfml code. The actual variable values aren&apos;t important.

&lt;code&gt;
&lt;cffile action=&quot;rename&quot; source=&quot;#variables.tmpFileLocation#&quot; destination=&quot;#variables.dir#/#variables.photoid#.jpg&quot;&gt;
&lt;/code&gt;

So I checked and doubled check the source url, and manually browsed to the directory and viewed it. The file was right there! I had a wander around online and found that this isn&apos;t a new issue, but more a bad error report.

The error isn&apos;t actually relating to the &apos;source&apos; attribute at all, but rather the &apos;destination&apos; attribute. In this case it was a file/folder permissions problem. (I didn&apos;t have write access). It was simply a case of Coldfusion server reporting it incorrectly.
				
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>File Interactions</category>
				
				<pubDate>Tue, 01 Sep 2009 17:01:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/9/1/Incorrect-error-message-reporting-using-CFFile-action-rename</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Finding the system file storage in AIR</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/7/28/Finding-the-system-file-storage-in-AIR</link>
				<description>
				
				When progamming an AIR application, you may want to make use of the applicationStorageDirectory available via the flash.filesystem package to store temporary files/folders.  You can find where your system is storing these files by doing something like the following:

&lt;code&gt;
var f:File = File.applicationStorageDirectory.resolvePath(&quot;Test.txt&quot;);
trace(f.nativePath + &apos; is where my file is stored&apos;);
&lt;/code&gt;

This will give you an absolute path to the local system file storage location. Handy for multi platform applications, as Pc and MAC based systems will use different default storage directories.
				
				</description>
				
				
				<category>Development</category>
				
				<category>AIR</category>
				
				<category>File Interactions</category>
				
				<category>RIA</category>
				
				<pubDate>Tue, 28 Jul 2009 12:00:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/7/28/Finding-the-system-file-storage-in-AIR</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Function for getting the last modified date of a template</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/7/3/Function-for-getting-the-last-modified-date-of-a-template</link>
				<description>
				
				Whilst looking at creating dynamic Sitemaps for Google bot spidering I found that I needed to populate an XML node with the last modified date of the templates. I figured there must be a programmatic way of doing this, so after some searching around this is what I ended out with:

&lt;code&gt;
&lt;cfset mod_time = createObject(&quot;java&quot;, &quot;java.util.Date&quot;).init(createObject(&quot;java&quot;, &quot;java.io.File&quot;).init(getcurrenttemplatepath()).lastModified())&gt;
&lt;/code&gt;

This creates a java object, using the date and file utilities we can use &apos;getcurrenttemplatepath()&apos; to provide the path data, finally referencing the lastModified property.

A handy and relatively quick way of getting the last modified date.

It is a bit of a mouthful though, so might be easier to create it as a handy referencable object:

&lt;code&gt;
&lt;cffunction name=&quot;modStamp&quot; access=&quot;public&quot; returntype=&quot;date&quot; output=&quot;no&quot; hint=&quot;Gets the last mod date of a file, returns a ts&quot;&gt;
	&lt;cfargument name=&quot;file&quot; type=&quot;string&quot; required=&quot;yes&quot; hint=&quot;File to get mod date&quot;&gt;
		&lt;cfset var mod_time = now()&gt;
		
		&lt;cfif fileexists(arguments.file)&gt;
			&lt;cfset mod_time = createObject(&quot;java&quot;, &quot;java.util.Date&quot;).init(createObject(&quot;java&quot;, &quot;java.io.File&quot;).init(arguments.file).lastModified())&gt;
		&lt;/cfif&gt;
		
	&lt;cfreturn mod_time&gt;
&lt;/cffunction&gt;

&lt;/code&gt;

Then you can just do:

&lt;code&gt;&lt;cfset variables.fileMod = modStamp()&gt;&lt;/code&gt;
				
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>File Interactions</category>
				
				<category>Web technologies</category>
				
				<pubDate>Fri, 03 Jul 2009 13:59:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/7/3/Function-for-getting-the-last-modified-date-of-a-template</guid>
				
				
			</item>
			
		 	
			</channel></rss>