• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How does one upload a file from flex to a cfc

Enthusiast ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

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.

TOPICS
Flash integration

Views

3.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Oct 04, 2010 Oct 04, 2010

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():vo

...

Votes

Translate

Translate
Advisor ,
Oct 04, 2010 Oct 04, 2010

Copy link to clipboard

Copied

HI,

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

thanks

Johnny

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 04, 2010 Oct 04, 2010

Copy link to clipboard

Copied

nope

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2010 Oct 04, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 04, 2010 Oct 04, 2010

Copy link to clipboard

Copied

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_Progress);
                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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2010 Oct 04, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 04, 2010 Oct 04, 2010

Copy link to clipboard

Copied

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-application.html

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

Thanks

Johnny

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 06, 2010 Oct 06, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 07, 2011 Feb 07, 2011

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation