Solved

Upload file to the server using flex with an ColdFusion Script

Posted on 2009-05-18
3
1,335 Views
Last Modified: 2013-12-24
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.

http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/

http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_7.html
FileUploadScript.cfm

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"/>

			</mx:AddChild>

 

			public var fileRef:FileReference;

			public const FILE_UPLOAD_URL:String = "http://localhost:8500/components/FileUploadScript.cfm";

 

	       private function uploadMyFile():void{		

				fileRef.browse();

	       }

 

			private function selectHandler(event:Event):void

			{						

			    try

			    {

				    fileRef.upload(new URLRequest(FILE_UPLOAD_URL));		    	

			    }

			    catch (error:Error)

			    {

			        Alert.show("Unable to upload file.");

			    }

			    

			}

			

			private function completeHandler(event:Event):void

			{				

			    Alert.show("uploaded");

			}
 

			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

0
Comment
Question by:mhendrix
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Jones911 earned 500 total points
ID: 24417539
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.
0
 

Author Closing Comment

by:mhendrix
ID: 31582820
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?



0
 
LVL 19

Expert Comment

by:Jones911
ID: 24420735
If you post a  screen shot of the folder setup and the import statements I mght be able to help
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to get function 52 100
.dwt files not viewable in browser - why? 2 75
Coldfusion retrieve dynamic values 1 30
Passing value to a stored procedure 8 92
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now