A few days ago wrote a JSP page to upload files using Ajaxfileupload. Now the Flex upload page is also shared:
Front Page
<?xml version= "1.0" encoding= "Utf-8"? ><s:hgroup xmlns:fx= "<a target=_blank href=" http://ns.adobe.com/ mxml/2009 ">http://ns.adobe.com/mxml/2009</a>" xmlns:s= "library://ns.adobe.com/flex/ Spark " xmlns:mx=" library://ns.adobe.com/flex/mx "creationcomplete=" hgroup1_ Creationcompletehandler (Event) " width=" 100% "height=" > <fx:Script> <! [Cdata[ import Mx.collections.arraylist; import mx.controls.Alert; import mx.events.flexevent; private var file:filereference = new FileReference; public var filelist:arraylist; public var manualcheck:manualcheck; protected function Hgroup1_creationcompletehandler (event:flexevent):void { //TODO auto-generated Method Stub// file.addeventlistener ( Dataevent.upload_complete_data,fileuploadcompletehandler); file.addeventlistener (Event.select, fileselect); // File.addeventlistener (Ioerrorevent.io_error,uploaderror); } protected function Button2_clickhandler (event:mouseevent): void { / /browse file.browse (); } private function Fileselect (e:event):void { if ( Filelist.getitemindex (file) = =-1) { filelist.additem (file); } filename.text = file.name; } // Private Function Fileuploadcompletehandler (e:dataevent): void{ // / / } private function Uploaderror (e:ioerrorevENT): Void{ this.cursormanager.removebusycursor (); //Gets the background error message alert.show ("Upload error. "," hint "); } protected function button3_ ClickHandler (event:mouseevent): void { //Delete Filelist.removeitem (This.file); manualcheck.group.removeelement (this); } ]]> </fx:Script> <fx:Declarations> <!--place non-visual elements (such as services, value objects) here--> </fx:declarations> <s:textinput id= "FileName" Width= "/> <mx:button" label= "Browse" click= "Button2_clickhandler (event)" fontweight= "bold" overskin= "@Embed (source= '/assets/dfpbtn/btnliulan2.png ')" skin= "@Embed (source= '/assets/dfpbtn/btnliulan.png ')"/> < Mx:button click= "Button3_clickhandler (event)" overskin= "@Embed (source= '/assets/ Dfpbtn/deletebtn2.png ') " skin=" @Embed (source= '/assets/dfpbtn/deletebtn.png ') "/ ></s:HGroup>
As
var file:filereference = Filelist.getitemat (i) as Filereference;var request:urlrequest=new URLRequest ("s/upload/ UploadFile "); Request.data=new urlvariables (); request.data.orderredorecord=n;try{ file.upload (Request, "file");} catch ( Error:error) {issuccess = false; Alert.show ("File upload failed"); }
Background Java:
@RequestMapping (value = "/uploadfile") @ResponseBody () public String uploadfiles (@RequestParam (value = "File") Multipartfile file) {string result = "", if (!file.isempty ()) {try {String attachname = File.getoriginalfilename (); logger. info (attachname); String FilePath = "Your path";//Omit Business code//fileutils.savedatatofile (File.getbytes (), filePath); result = "Upload succeeded";} catch (Exception e) {//TODO auto-generated catch Blockresult = "Upload Failed"; E.printstacktrace ();}} return result;}
Flex Upload File