gsr
12/08/2024, 2:31 PM<cffunction name="handleFileUpload" access="private" returntype="any">
<cfargument name="uploadDir" type="string" required="true">
<cfargument name="photoField" type="any" required="false">
<cfset var result = {
files = [],
errors = []
}>
<cfif structKeyExists(arguments, 'photoField') AND len(arguments.photoField)>
<cfif isArray(arguments['photoField'])>
<!--- Handle multiple file upload --->
<cfloop array="#arguments['photoField']#" index="file">
<cfset var filePath = arguments.uploadDir & "/" & file.serverFile>
<cfif file.fileSize GT 0 AND len(file.fileName)>
<cffile
action="upload"
fileField="#arguments.photoField#"
destination="#arguments.uploadDir#"
nameconflict="makeunique"
accept="image/*"
result="local.uploadResult">
<cfif structKeyExists(local.uploadResult, "serverFile")>
<cfset arrayAppend(result.files, {
fileName = file.fileName,
filePath = filePath,
serverFile = local.uploadResult.serverFile
})>
</cfif>
<cfelse>
<cfset arrayAppend(result.errors, {
fileName = file.fileName,
error = "No file selected"
})>
</cfif>
</cfloop>
<cfelse>
<!--- Handle single file upload --->
<cfset var filePath = arguments.uploadDir & "/" & arguments['photoField'].serverFile>
<cfif arguments['photoField'].fileSize GT 0 AND len(arguments['photoField'].fileName)>
<cffile
action="upload"
fileField="#arguments.photoField#"
destination="#arguments.uploadDir#"
nameconflict="makeunique"
accept="image/*"
result="local.uploadResult">
<cfif structKeyExists(local.uploadResult, "serverFile")>
<cfset arrayAppend(result.files, {
fileName = arguments['photoField'].fileName,
filePath = filePath,
serverFile = local.uploadResult.serverFile
})>
</cfif>
<cfelse>
<cfset arrayAppend(result.errors, {
fileName = arguments['photoField'].fileName,
error = "No file selected"
})>
</cfif>
</cfif>
<cfelse>
<cfset arrayAppend(result.errors, {
fileName = "",
error = "No files uploaded"
})>
</cfif>
<cfreturn serializeJSON(result)>
</cffunction>
error i am getting is:
additional*Struct (ordered)*DetailstringErrorCodestring0Extended_InfostringExtendedInfostringMessagestringNo matching method for String.isSERVERFILE() found. there are no methods with this name.quetwo
12/08/2024, 2:49 PMarguments['photoField'] is coming in as a string instead of s struct/object right after your else statement.gsr
12/08/2024, 2:58 PMReuben Brown
12/08/2024, 4:19 PMquetwo
12/08/2024, 8:04 PMrodyon
12/09/2024, 11:05 AM<form method="post" enctype="multipart/form-data">gsr
12/11/2024, 12:33 PMShawn Grigson
12/12/2024, 2:51 PM<cfset var filePath = arguments.uploadDir & "/" & arguments['photoField'].serverFile>
Almost certain, this is your issue:
arguments['photoField'].serverFile
Is photoField a string, or a struct? You're referencing it as both.
Note the error:
"No matching method for String.isServerFile()"
The string in this case is arguments['photoField']. A Java String datatype doesn't have 'isServerFile' as a function.Shawn Grigson
12/12/2024, 2:52 PMfileField="#arguments.photoField#" It's clearly intended to be a string, trying to reference it as a struct is the issue.Shawn Grigson
12/12/2024, 2:54 PMlocal.uploadResult.serverFileShawn Grigson
12/12/2024, 2:55 PMarguments["photoField"].fileName is going to blow up, too