Using FORM.getPartsArray() in Lucee

353 Views Asked by At

Currently I'm working on a project to convert source code from ColdFusion to Lucee. I found an error occurs in Lucee, when using FORM.getPartArray(). Does Lucee have a similar function that can replace FORM.getPartArray()?

Example code:

<cfset var fileExt = 'png'>
<cfset var tmpPartsArray = FORM.getPartsArray() />
<cfif IsDefined("tmpPartsArray")>
    <cfloop array="#tmpPartsArray#" index="local.tmpPart">
        <cfif local.tmpPart.isFile() AND local.tmpPart.getName() EQ arguments.formField>
            <cfset fileExt = ListLast(local.tmpPart.getFileName(), ".")>
        </cfif>
    </cfloop>
</cfif>
2

There are 2 best solutions below

2
SOS On BEST ANSWER

You could also try FORM.getFileItems(). That array seems to contain only file fields.

<cfset Local.filesArray = FORM.getFileItems() />
<cfloop array="#Local.filesArray#" index="local.currFile">
    <cfset fileExt = ListLast(local.currFile.getName(), ".")>
</cfloop>

What is the purpose of the original code? As the file was already uploaded to the server, you could also move it to a safe directory with <cffile action="upload"> and check cffile.serverFileExt instead.

1
Alex Baban On

Not exactly.

FORM.getPartsArray() is proprietary to Adobe, in Lucee you can try FORM.getRaw() but you'll probably have to do some work.

getName() will match but I'm not sure about the other ones.