I have a very simple code which uploads the file
<form method="post" action="upload.cfm" enctype="multipart/form-data">
<table>
<tbody>
<tr>
<td><input type="file" name="uploadFile" id="uploadFile"></td>
</tr>
<tr>
<td><input type="submit" name="Upload" id="Upload" value="Upload"></td>
</tr>
</tbody>
</table>
</form>
and my upload.cfm as:
<cfif isDefined('form.upload')>
<cfset results = uploadAndInsertData('#FORM.uploadFile#')>
</cfif>
upload and insert function as;
<cffunction name="uploadAndInsertData" access="public" returntype="any">
<cfargument name="uploadedFile" type="any" required="true">
<cfset targetFolder = ExpandPath('documents')>
<cfset success = true>
<cfset cffile = UploadFile(
FileField = "uploadedFile",
destination = "#targetFolder#"
)>
<cfset fileContent = fileRead("#targetFolder##uploadedFile#")>
</cffunction>
UploadFile is a function from cflib.org
https://cflib.org/udf/uploadFile
and it keeps throwing me an error,
The form field uploadedFile did not contain a file.
20 :
21 : <!--- Upload to temp directory. --->
22 : <cffile action="upload" filefield="#Arguments.FileField#" destination="#Arguments.TempDirectory#" nameconflict="MakeUnique">
23 : <cfset tempPath = ListAppend(cffile.ServerDirectory, cffile.ServerFile, "\/")>
24 :
The issue is with the way you are passing
FileField
to the functionUploadFile
.FileField
should be the name of theinput[type="file"]
which isuploadFile
in your case.Other than that, you don't need to a call
uploadAndInsertData('#FORM.uploadFile#')
there is no need to pass this to the function just douploadAndInsertData()
.<cffile aciton="upload">
automatically takes the form field based on the name of the field.You'll need to change
to