Skip to main content
Participating Frequently
February 8, 2011
Question

Confused about cffileupload & cffile action="uploadall"

  • February 8, 2011
  • 2 replies
  • 4166 views

I'm trying to figure out how to use cffileupload so I have a braindead .cfm file:

<cffileupload 
    url="uploadFiles.cfm"
    progressbar="true"
    name="myupload"
    addButtonLabel = "Add File"
    clearButtonlabel = "Clear All"
    width=600
    height=400
    title = "File Upload"
    maxuploadsize="30"
    extensionfilter="*.jpg, *.png, *.flv, *.txt"
    BGCOLOR="##FFFFFF"
    MAXFILESELECT=10
    UPLOADBUTTONLABEL="Upload now"/>

which is the one from the documentation page. Where I'm losing it is in the processing file.

If the file contains only:

<cffile action="uploadall" destination="c:/testload" nameConflict="overwrite">

the files upload and no problems. The issue is that I want to do additional processing on

each file after it arrives. I've tried this:

<cfoutput>
<cffile action="uploadall" destination="c:/testload" nameConflict="overwrite">

<cfimage source="C:/testload/#CFFile.serverfile#" action="resize" width="300" height="" destination="c:/testload/small.jpg" overwrite="yes">

</cfoutput>

and the CFFILEUPLOAD status bar shows an HTTP 500 error.

Is the uploadFiles.cfm called for each file individually, i.e., if I upload

3 files, is it invoked three times? If so, how do I access the server side file name? If I use

CFFILE.serverFile, I get a HTTP 500 error. Or is this an array or CFFILE structures? I've

tried multiple different approaches and all I get is the HTTP 500 error. None of the examples

I can find explain this or show readable code. Thanks.

    This topic has been closed for replies.

    2 replies

    Participant
    August 25, 2015

    I was able to get it working without the flash uploader (decided to go away from all UI cf related) and went with the basic input file with multiple. That returned me an array which I was able to parse through and get what I need. What a pain this was! I can't believe the lack documentation on this.

    <cffile action="uploadall"
    destination="\\#Variables.sServerName#\#filepath#"
    nameConflict = "MakeUnique"
    result="myUpload">
    <cfoutput>
    <cfloop from="1" to="#arrayLen(myUpload)#" index="i">
      <cfset data = myUpload>
      <cfloop collection="#data#" item="serverFile">
      <cfif serverFile EQ "serverFile">

      

                 do my thing with the newly uploaded filename
     

      

      </cfif>
      </cfloop>
    </cfloop>

    Thanks guys!

    Fernis
    Inspiring
    February 9, 2011

    This gave me gray hairs too when I learned this, since the docs on this one suck and blow golf balls through a garden hose.

    As you know, CFFILE UPLOADALL handles multiple file uploads at once. But what ColdFusion documentation really frustratingly skips, is explaining to you how things are different when you use the Flash upload control.

    > Is the uploadFiles.cfm called for each file individually, i.e., if I upload 3 files, is it invoked three times?

    Yes.

    What I'd do for debugging is to minimize the processing in the handling template which processes the uploads. Also, make sure the document does not output anything.

    Start simply with

    <cffile 
        action = "uploadAll"
        destination = "#VIDEO_UPLOAD_FOLDER#"
        nameConflict = "makeUnique"
        result = "myUpload">

    >If so, how do I access the server side file name?

    As the documentation explains, the upload results are in an array of structures. But wait! *screeeeeech!* As I said, the handling file gets executed once per file. So the array always has a length of one (1).

    Thus, after each file uploaded and handled in the background, the server side filename is contained by myUpload[1].serverFile .

    My personal approach in applications is to save newly uploaded file information into a database, flagged as not processed yet - then throw the user after the upload to the processing page. For this, the ColdFusion flash file upload control luckily has the oncomplete attribute, which can use a Javascript function to throw you to the next page after an upload.

    Hope this helps,

    -Fernis

    fl_guyAuthor
    Participating Frequently
    February 9, 2011

    Now that's dumb! I thought it would at least create an array

    of N elements. The best way would be to have the results

    available for a . Oh well, at least now

    I know! Thanks for the help!

    Steve Haeffele

    130 Riviera Dunes Way #1001

    Palmetto, FL 34221

    Tel: 941-531-7227

    Cell: 408-394-3831

    Fax: 941-866-2628

    e-mail: steve.haeffele@oilartist.com