Flex Upload File

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.