-
1. Re: How does one upload a file from flex to a cfc
jfb00 Oct 4, 2010 5:29 AM (in response to nikos101)HI,
I'm tryin to do this now, did you figure this out?
thanks
Johnny
-
2. Re: How does one upload a file from flex to a cfc
nikos101 Oct 4, 2010 5:32 AM (in response to jfb00)nope
-
3. Re: How does one upload a file from flex to a cfc
Adam Cameron. Oct 4, 2010 5:46 AM (in response 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
-
4. Re: How does one upload a file from flex to a cfc
jfb00 Oct 4, 2010 5:53 AM (in response 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_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
-
5. Re: How does one upload a file from flex to a cfc
Adam Cameron. Oct 4, 2010 6:10 AM (in response 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
-
6. Re: How does one upload a file from flex to a cfc
jfb00 Oct 4, 2010 6:21 AM (in response 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-application.html
But like I said before, i want to use the cfc.
Thanks
Johnny
-
7. Re: How does one upload a file from flex to a cfc
jfb00 Oct 6, 2010 3:39 AM (in response 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
-
8. Re: How does one upload a file from flex to a cfc
kure69 Feb 7, 2011 5:57 PM (in response 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


