Using cffile to try to upload a file from inside a CFC causes an error unless a small and non-intuitive syntax is used.
You must pass the name of the FORM filefield into the CFC as a string and then surround the resulting ARGUMENT variable with "#" so that cffile's filefield attribute is provided the name of the FORM filefield as a string. This differs from the usual syntax for the filefield attribute where "#" is not used.
You want to create a CFC to handle a file upload (or uploads) but CF throws an error that the file does not exist. Using CFFile with the standard syntax does not work within a CFC.
Here's an example of the standard syntax for using cffile.
<cffile action="upload" destination="/path/to/destination/folder/" filefield="FORM.fileToUpload" nameconflict="makeunique">
What is important to note here is that the filefield attribute is expecting the name of the FORM field referring to the file to be uploaded file as a string.
When using cffile inside a CFC, you might be tempted to do this (below) as it seems like the straightforward way to do it.
<cfcomponent output="no">
<cffunction name="uploadFile"
access="public"
output="no"
returntype="string">
<cfargument name="fileToUpload" type="string" required="no">
<cfset var cffile = "">
<cffile action="upload"
destination="/path/to/destination/folder/"
filefield="ARGUMENTS.fileToUpload"
nameconflict="makeunique">
<cfreturn cffile.clientFile>
</cffunction>
</cfcomponent>
Here the arguments variable (that the FORM's file variable has been passed into) has simply been substituted for the FORM.fileToUpload variable in the cffile tag. But this gives an error.
Instead, ARGUMENTS.filetoUpload needs to be enclosed in "#" so that the variable is processed by ColdFusion and CF gets the name of the actual (form) variable pointing to the uploaded file as a string.
<cfcomponent output="no">
<cffunction name="uploadFile"
access="public"
output="no"
returntype="string">
<cfargument name="fileToUpload" type="string" required="no">
<cfset var cffile = "">
<cffile action="upload"
destination="/path/to/destination/folder/"
filefield="#ARGUMENTS.fileToUpload#"
nameconflict="makeunique">
<cfreturn cffile.clientFile>
</cffunction>
</cfcomponent>
This simple change will get your cffile tag working inside you CFC
+