Upload file to the server using flex with an ColdFusion Script

I am looking for an example on how to upload a file from my Flex app to a server. I have tried many examples but just can't seem to get it to work.

Currently (with the code attached) I can browse and when I select a file and hit open it does nothing ( no error, no message) .

Also tried to put my upload file code in a CFC and send the file info to the CFC - My problem with that is it was looking for a form object

Anyway,  either solution will work (uploading using a CFC or having a CFM script)

Here are a couple of links that I have tried.


This is my one line script just to test the upload
<cffile action="upload" filefield="Filedata" destination="#ExpandPath('./')#" nameconflict="OVERWRITE" />
Flex Code: Bits and Pieces
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#C4C4C4, #FFFFFF]" currentState="Login" width="1000" borderStyle="solid" height="100%" x="0" y="0" verticalAlign="top" horizontalAlign="center">
			<mx:AddChild position="lastChild">
				<mx:Button label="Upload File" click="uploadMyFile();" x="428" y="88"/>
			public var fileRef:FileReference;
			public const FILE_UPLOAD_URL:String = "http://localhost:8500/components/FileUploadScript.cfm";
	       private function uploadMyFile():void{		
			private function selectHandler(event:Event):void
				    fileRef.upload(new URLRequest(FILE_UPLOAD_URL));		    	
			    catch (error:Error)
			        Alert.show("Unable to upload file.");
			private function completeHandler(event:Event):void
			private function init():void{	
				fileRef = new FileReference();								
				fileRef.addEventListener(Event.SELECT, selectHandler);
				fileRef.addEventListener(Event.COMPLETE, completeHandler);				
				fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);

Open in new window

Who is Participating?
Jones911Connect With a Mentor Commented:
Check this article out: http://www.adobe.com/devnet/coldfusion/articles/multifile_upload.html

If your still stuck come back and I'll help some more but this article is really good.
mhendrixAuthor Commented:
Thanks. I had looked at this example before but when I went back it all made sense. The only problem I had is that I had to move the .as file into my personal components directory because flex builder wouldn't recognize it in the com.... directory? Any idea why?

If you post a  screen shot of the folder setup and the import statements I mght be able to help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.