Skip to main content
DharameshShrivastava
Participating Frequently
September 7, 2014
Answered

cffileupload progressbar shows error although files are uploaded

  • September 7, 2014
  • 2 replies
  • 1208 views

i am using cf11 developer edition...

i am using cffileupload for uploading multiple files...

bottom bar says--- uploaded 4 of 4 files

but individual progress bar after reaching to 99% Shows ERROR its color is red

bottom bar is green

how to resolve it ?BKBKColdFusion@

    This topic has been closed for replies.
    Correct answer BKBK

    DharameshShrivastava wrote:

    destination ="#getdirectoryFromPath(expandPath("CFFileUpload.cfm"))#/Upload/#FORM.FILENAME#"

    The destination should be a directory, not a file. So, use getdirectoryFromPath(expandPath('CFFileUpload.cfm'))#/Upload/. Check beforehand that the directory exists.

       <cfset returnValue=
    

        {

          STATUS=200

        , MESSAGE = "Successfully Uploaded"

        , FILENAME = CFFILE.SERVERFILE

        }>

      

    I doubt whether the structure cffile exists when you are using <cffile action="uploadAll">. That is because you are then uploading multiple files. You should use instead the result attribute, which stores the properties of the uploaded files in an array whose elements correspond to the respective files.

    In any case, why would you want to output anything in the page UploadHandler.cfm anyway? You never get to see it! The page you currently see is CFFileUpload.cfm. In my opinion, you could just simplify the page content to

    UploadHandler.cfm

    <cfsilent>

           <cffile action="uploadall" filefield="FILEDATA" nameconflict="makeunique" destination ="#getdirectoryFromPath(expandPath('CFFileUpload.cfm'))#/Upload/" />

    2 replies

    DharameshShrivastava
    Participating Frequently
    September 7, 2014

    i am using cf11 developer edition.

    i am using cffileupload for uploading multiple files.

    bottom bar says--- uploaded 4 of 4 files

    but individual progress bar after reaching to 99% Shows ERROR its color is red

    bottom bar is green

    how to resolve it ?

    1.CFFileUpload.cfm

    <cfajaximport tags="cfmessagebox" />

    <html>

       <head>

         <title>CFFILEUPLOAD</title>

           <script type="application/javascript" language="javascript"   src="JS/advanceFileUploadHandling.js"> </script>

       </head>

    <body>

      <cffileupload

         url="UploadHandler.cfm"

         extensionfilter=".jpg,.png,.jpeg,.html,.bmp"

         maxuploadsize="10"

         title="Upload Html And Image Files"

         width="700px"

         addbuttonlabel="select files"

         uploadbuttonlabel="upload files"

         deletebuttonlabel="delete selected files"

         clearbuttonlabel="remove all files"

          stoponerror ="false"

         oncomplete="fileComplete"

         onUploadComplete="uploadComplete"

    />

    </body>

    </html>

    2.UploadHandler.cfm

    <cfsilent>

           <cffile action="uploadall" filefield="FILEDATA" nameconflict="makeunique" destination ="#getdirectoryFromPath(expandPath("CFFileUpload.cfm"))#

    /Upload/#FORM.FILENAME#"

    />

       <cfset returnValue=

        {

          STATUS=200

        , MESSAGE = "Successfully Uploaded"

        , FILENAME = CFFILE.SERVERFILE

        }>

       

       </cfsilent>

       <cfoutput>#SerializeJSON(returnValue)#</cfoutput>

    3.advanceFileUploadHandling.js

    var errorFiles = []

    var fileComplete = function(result)

    {

        if(result.STATUS !=200)

        {

            errorFiles.push(result.FILENAME);

        }

       

    }

    var uploadComplete = function()

    {

        var icon = 'info';

        var message =' all were successfully uploaded';

        if(errorFiles.length !=0)

        {

            icon='error';

            message='The following files were not uploaded:<br/><br/>';

           for(i=0; i=errorFiles.length; i++)

             {

               message +='  &bull;' + errorFiles+'<br>';

             }

           errorFiles=[];

        }

         if(!Coldfusion.MessageBox.isMessageboxDefined('uploadMessage'))

         {

            ColdFusion.MessageBox.Create('uploadMessage','alert','Upload Complete',   message,empty,{icon: icon,                 modal: true});

        }

        else

        {

            ColdFusion.MessageBox.update('uploadMessage',{icon: icon,modal: true});

            ColdFusion.MessageBox.updateMessage('uploadMessage',message);

        }

        ColdFusion.MessageBox.show('uploadMessage');

    }

    var empty = function()

    {}

    BKBK
    Community Expert
    Community Expert
    September 7, 2014

    Have you followed my suggestions? If so, what was the result?

    BKBK
    Community Expert
    Community Expert
    September 7, 2014

    The log files will likely give you a clue. Look, in particular, at the files exception.log, coldfusion-out.log and application.log.

    The first thought that comes to mind is: the nameConflict attribute of cffile. You should use either <cffile nameConfilct="overwrite"> or <cffile nameConfilct="makeUnique">. They work as follows:

    Overwrite: replaces previously uploaded file of same name.

    MakeUnique: creates a new, unique filename for the upload.

    DharameshShrivastava
    Participating Frequently
    September 7, 2014

    There Seems issue with .SERVERFILE as i checked from log.

    but what i should use instead?

    BKBK
    Community Expert
    Community Expert
    September 7, 2014

    Cffile.serverfile fails because there is more than one uploaded file. You perhaps missed my explanation. Here it is again:

    You should use instead the result attribute, which stores the properties of the uploaded files in an array whose elements correspond to the respective files.

    In any case, why would you want to output anything in the page UploadHandler.cfm anyway? You never get to see it! The page you currently see is CFFileUpload.cfm.

    You could implement the result attribute as follows:

    UploadHandler.cfm

           <cffile action="uploadall" filefield="FILEDATA" nameconflict="makeunique" destination ="#getdirectoryFromPath(expandPath('CFFileUpload.cfm'))#/Upload/" result="uploadResult" />

    When the cffile action is 'uploadAll', the result attribute is an array of structures. Each element of the array corresponds to an uploaded file, and consists of the information that you would normally expect from the cffile structure. What you could actually do to implement this is to log it. For example, add the line,

    <cflog file="multiUpload" text="#serializeJSON(uploadResult)#">

    After you run this, have a look at multiUpload.log