Skip to main content
Inspiring
November 11, 2009
Question

CF9 <cffile> changes???

  • November 11, 2009
  • 3 replies
  • 1310 views

I have a flex app that would send a file to a cfm and it would resize it, rename it and upload/write the file to the server.  In flex I could put a "UPLOAD_COMPLETE_DATA" listener and an error listener on the file I was sending and CF would return back the event.  We are switching over to CF9 and it seems that CF9 no longer sends back an event, so the app doesnt know when the file has been uploaded.  I made a simple version of this to confirm, and it works fine in 8 but does not work in 9.  Does anyone know what has changed, or a way to get around this?

    This topic has been closed for replies.

    3 replies

    hanchan07Author
    Inspiring
    November 12, 2009

    Finally found the issue, apparently in CF9, Coldfusion does not announce the Upload_complete_data event unless there is something output on the page, in previous versions it would just do it.  So at the end of the page simply adding <cfoutput>.</cfoutput> is all that was needed to get the event.  Hope this helps anybody who runs into the problem.

    Inspiring
    November 12, 2009

    I'd call that a bug (broken backwards compat will be considered a bug by Adobe), and suggest you raise it accordingly:

    http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html

    --

    Adam

    hanchan07Author
    Inspiring
    November 11, 2009

    While playing around with this a bit more, I found a work around, instead of using DataEvent.UPLOAD_COMPLETE_DATA, using the ProgressEvent.PROGRESS listener and then simply checking if the event.bytesLoaded == event.bytestotal and then going from there works.  But if anybody knows why either the cffile or the cfm itself is not passing the httpstatus for the file write or upload, or what has changed, please post it.

    Inspiring
    November 11, 2009

    I made a simple version of this to confirm, and it works fine in 8 but does not work in 9.

    Can you post this code?

    --

    Adam

    hanchan07Author
    Inspiring
    November 11, 2009

    *As a note: The files are getting writen to the folder, but I get nothing back from CF9 saying that they are.

    The cfm contains this code:

    <cftry>

        <cfset fileName="E:\ColdFusion9\wwwroot\tempDisk\avatar\profile\" & "#form.newFileName#">   
           
        <cfif IsDefined("form.filedata")>
       
            <cffile action="upload"
                filefield="form.filedata"
                destination="#fileName#"
                nameconflict="overwrite"
                accept="application/octet-stream"
                />
           
        <cfelseif IsDefined("form.fileBytes") >   
           
            <cffile action="write"
                file="#fileName#"
                output="#ToBinary(form.fileBytes)#"
                addNewLine="false"
                nameconflict="overwrite">

            
        </cfif>
           
       
        <cfset fileName16="E:\ColdFusion9\wwwroot\tempDisk\avatar\profile\" & "16_" & "#form.newFileName#">
        <cfset fileName32="E:\ColdFusion9\wwwroot\tempDisk\avatar\profile\" & "32_" & "#form.newFileName#">
        <cfset fileName50="E:\ColdFusion9\wwwroot\tempDisk\avatar\profile\" & "50_" & "#form.newFileName#">
        <cfset fileName100="E:\ColdFusion9\wwwroot\tempDisk\avatar\profile\" & "100_" & "#form.newFileName#" >
       
            <cfimage
                action = "resize"
                source = "#fileName#"
                destination = "#fileName16#"           
                height = "16"
                width = "16"
                overwrite = "yes">
            <cfimage
                action = "resize"
                source = "#fileName#"
                destination = "#fileName32#"   
                height = "32"
                width = "32"
                overwrite = "yes">
            <cfimage
                action = "resize"
                source = "#fileName#"
                destination = "#fileName50#"           
                height = "50"
                width = "50"
                overwrite = "yes">
               
            <cfimage
                action = "resize"
                source = "#fileName#"
                destination = "#fileName100#"           
                height = "100"
                width = "100"
                overwrite = "yes">
               
            <cfimage
                action = "resize"
                source = "#fileName100#"
                destination = "#fileName#"           
                height = "100"
                width = "100"
                overwrite = "yes">
               
         <cffile action="delete" file="#fileName100#" >

    The flex code:

    //this is called after user selected file:

    private function handler_avatarImageFile_select( event:Event ):void
                {
                    avatarImageFile.removeEventListener( Event.SELECT, handler_avatarImageFile_select )

                    var urlVars:URLVariables = new URLVariables();
                    var request:URLRequest = new URLRequest( 'ProfileAvatarUploadHandler.cfm' );
                    request.method = URLRequestMethod.POST;
                    urlVars.newFileName = '19310' + avatarImageFile.type;
                    urlVars.enctype= 'multipart/form-data';
                    request.data = urlVars;
                    avatarImageFile.addEventListener( IOErrorEvent.IO_ERROR, handler_avatarImageFile_ioError );
                    avatarImageFile.addEventListener( DataEvent.UPLOAD_COMPLETE_DATA, handler_avatarImageFile_uploadCompleteData );
                    avatarImageFile.upload( request, 'fileData' );
                }
               
               
                private function handler_avatarImageFile_ioError( event:IOErrorEvent ):void
                {
                  
                    Alert.show( 'The image that you selected could not be uploaded.  Please try again.', 'Error' );
                   
                    avatarImageFile.removeEventListener( IOErrorEvent.IO_ERROR, handler_avatarImageFile_ioError );
                    avatarImageFile.removeEventListener( DataEvent.UPLOAD_COMPLETE_DATA, handler_avatarImageFile_uploadCompleteData );
                }
               
                private function handler_avatarImageFile_uploadCompleteData( event:DataEvent ):void
                {
                  
                    avatarImageFile.removeEventListener( IOErrorEvent.IO_ERROR, handler_avatarImageFile_ioError );
                    avatarImageFile.removeEventListener( DataEvent.UPLOAD_COMPLETE_DATA, handler_avatarImageFile_uploadCompleteData );
                   
                    pic.load(path+'19310'+avatarImageFile.type);
                   
                }

    Inspiring
    November 11, 2009

    Sorry I was more expecting a minimalist, self-contained body of code that demonstrates the problem without having all the trappings of being chopped out of someone's application.

    Just enough code for someone to:

    a) run without modification;

    b) demonstrates the problem;

    c) without any other code that is not part of demonstrating the problem.

    --

    Adam