Skip navigation
Currently Being Moderated

How does one upload a file from flex to a cfc

Jun 21, 2010 8:46 AM

How does one upload a file from flex to a cfc?   Can you do the file upload via remote object? I usually do uploads cia cfm but prefer the asnc capabilities of remote object calls.

 
Replies
  • Currently Being Moderated
    Oct 4, 2010 5:29 AM   in reply to nikos101

    HI,

    I'm tryin to do this now, did you figure this out?

    thanks

     

    Johnny

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 4, 2010 5:46 AM   in reply to nikos101

    Will something like this not work:

     

     

    <cfcomponent>

     

        <cffunction name="uploadFile" access="remote" output="false" returntype="void">
            <cffile action="upload" filefield="myFile" destination="C:\temp\" nameconflict="makeunique">
        </cffunction>
       
    </cfcomponent>

     

    (where myFile is the name of the formfield containing the uploaded file's name).

     

    This works fine from an HTML-originated POST, so I would assume it would work from a Flash-originated POST too: the CF server won't care (or even know).

     

    Also, I'm intrigued by what you mean by the "asnc capabilities of remote object calls" comment.  Just that I don't understand what you mean, I mean.  I'm not questioning it.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 4, 2010 5:53 AM   in reply to Adam Cameron.

    Hi,

    The issue here is myFile. For flex we need to pass this name as paramenter becuase it's not html form item like:

     

    <cfcomponent>

     

        <cffunction name="uploadFile" access="remote" output="false" returntype="void">

        <cfargument name="file" required="Yes" type="any">
            <cffile action="upload" filefield="#arguments.file#" destination="C:\temp\" nameconflict="makeunique">
        </cffunction>
    </cfcomponent>

     

    From flex I'm getting the file using fileReference like:

    private function browseAndUpload():void
                {
                    fileReference = new FileReference();
                    fileReference.addEventListener(Event.SELECT,fileReference_Select);
                    fileReference.addEventListener(Event.CANCEL,fileReference_Cancel);
                    fileReference.browse();
                }
               
                private function fileReference_Select(event:Event):void
                {
                    fileReference.addEventListener(ProgressEvent.PROGRESS,fileReference_P rogress);
                    fileReference.addEventListener(Event.COMPLETE,fileReference_Complete) ;
                    fileReference.addEventListener(IOErrorEvent.IO_ERROR,onLoadError);
                   
                    //fileReference.upload(request);
                    fileName = fileReference.name;
                    myFile.htmlText = fileReference.name;
                    SM_RO.importNSA();
                }

     

    filerReference have an upload method to upload the file but I can't use that becuase I need to process my upload with my cfc.

    I'm getting an error:

    Failed to import the file. The cffile action="upload" requires forms to use enctype="multipart/form-data". Please also make sure the file is not open.

    I can't find the way to setup the enctype becuase again i can have html form items in flex, or I can?

    Thanks

     

    Johnny

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 4, 2010 6:10 AM   in reply to jfb00

    I'm making this up as I go along a bit, but I would not worry so much about the CF error message saying the form needs to have that enctype.  What it means is the HTTP request needs to have a content-type of multipart/form-data.  It doesn't matter how it gets to be sent like that... a form-tag attribute, or just setting the header via some other mechanism: neither the web server nor CF will know/care how it goes done.


    A case in point is that one doesn't need to post to that CFC method via a form... one could just as much post if via <cfhttp>.  There's no forms involved in doing it that way; just CF creating an HTTP request.

     

    Now... I don't know Flash from... err... Adam, but I'm "certain" that if CF received the request in the correct format (so the corrent content-type, and a field with a file in it), the CF side of things would work fine.

     

    It's just a matter of coercing Flex to do that for you with Flash.  Which might be a question for a Flex forum, not a CF one..?  The question, I think, is more "how do I upload a file using Flex" rather than "... to a CF server".

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 4, 2010 6:21 AM   in reply to Adam Cameron.

    Got it, I try flex forum but no help.

    It works fine if I use a cfm file like this example:

    http://askjayvir.blogspot.com/2008/07/sample-flex-file-upload-applicat ion.html

    But like I said before, i want to use the cfc.

    Thanks

     

    Johnny

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 6, 2010 3:39 AM   in reply to jfb00

    Hi All,

    I discover my issue here.

    Every time  I use filereference, it's using a new session and I lost my login. In  my application I'm using application.cfc with cflogin.

    I hope it's a way to keep my session using fileReference.

    Regards

     

    Johnny

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2011 5:57 PM   in reply to nikos101

    Hi all

     

    Is it possible to upload a file with a cfc from flex, if some can some one please post some code.

     

    Thanks Asen

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2011 7:13 PM   in reply to kure69
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points