Bug with Multiple <cffileupload> Controls and Different onComplete Handlers

A co-worker of mine has been bashing her head against a wall in recent days trying to figure out why a view with multiple <cffileupload> controls wasn't behaving properly. No matter what she did, a page with multiple <cffileupload> controls that also specified a different onComplete handler for each control always caused the last onComplete handler to be fired. She even made sure to have unique names for each file upload control.

It turns out that this is a completely reproducible bug in ColdFusion 9. Here's how you can replicate this bug:

<html>
<head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <title>cffileupload Bug Test</title>
   <script language="javascript">
<!--
   function uploadOneDone() {
      alert("uploadOneDone called");
   }
   
   function uploadTwoDone() {
      alert("uploadTwoDone called");
   }
//-->
</script>
</head>
<body>
<p>Upload One, calls uploadOneDone() when finished.</p>
<p><cffileupload url="upload.cfm" name="uploader1" onComplete="uploadOneDone" /></p>

<p>Upload Two, calls uploadTwoDone() when finished.</p>
<p><cffileupload url="upload.cfm" name="uploader2" onComplete="uploadTwoDone" /></p>

</body>
</html>

You'll need a file called upload.cfm in the same directory as this test page. It can be as simple as:

<cffile action="upload" destination="#ExpandPath('.')#" nameconflict="makeunique"/>

Upload a file using the first uploader on the page. Here is the result you'll get:

Results from cffileupload onComplete bug

The last onComplete handler is fired, no matter how many of the controls are added to the page.

Maybe we're doing something wrong here, and if we are, I'd love to know. In the meantime, I've opened this as bug #82396 in the ColdFusion bug tracker. Feel free to vote for it!

Comments
Dan G. Switzer, II's Gravatar While the docs don't explicitly say whether or not multiple callbacks can be used for multiple cffileupload tags, the event handler that's called does get passed an object which includes STATUS, MESSAGE and FILENAME. So, you could just always call the same event handler and then have your handler perform the appropriate action based on the FILENAME that was processed.

-Dan
# Posted By Dan G. Switzer, II | 3/10/10 11:48 AM
Brian's Gravatar Dan - that's very true, if we were interested only in the file name. In our particular situation, we need to know which cffileupload control was used as different controls deliver files to different places, and the results from each need to be handled differently, regardless of the name of the file that was uploaded.

One workaround that my co-worker came up with was to -- gulp -- use an iframe to insert each of the multiple cffileupload controls on the page. Not elegant, but it works.
# Posted By Brian | 3/11/10 1:09 PM
Brian's Gravatar FYI - bug #82396 has been confirmed by Adobe and is scheduled for ColdFusion 9.0.1.
# Posted By Brian | 3/17/10 8:04 AM
BlogCFC was created by Raymond Camden.

Creative Commons License
The content on http://www.iterateme.com/ is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.