Record-jquery uploadify File upload instance

Source: Internet
Author: User

Originally done is from the form of file upload, and later because of the need to use Ajax asynchronous, so contact with the jquery uploadify upload

Put code on it for reference

JS files that need to be introduced

    <href= "... /res/uploadify/uploadify.css "  rel=" stylesheet "  type=" Text/css"/>     <src= ".. /res/uploadify/jquery.uploadify.min.js "  type=" Text/javascript"></ Script >

Here is the HTML code

<type= " file" id= "File " name= "  file" />

Here's the jquery code

The blue part below is useless .

$ ("#file"). Uploadify ({height:14, swf: '/res/uploadify/uploadify.swf ', Uploader: '. /member/getallbyexcel ', width:100, filetypeexts: ' *.xls ', errormsg: ' Unsupported file format ', ButtonText: "Excel upload", Multi:false, Onuploadsuccess:function (File,data, state) {var jsondata =$.parsejson (da Ta.replace (/\\/g, "\\\\")); if (data.msg) {alert (unescape (data.msg)); Return } $.appendmainpic (Jsondata.images[0].url,jsondata.images[0].id); var Orgvalue = $ ("#Card_Pic_mainPic"). Val () + ""; orgvalue+= "," +jsondata.images[0].id; $ ("#Card_Pic_mainPic"). Val (Orgvalue); }, Onqueuecomplete:function (a,b,c) {}});

Here is the background code

@RequestMapping (value= "Getallbyexcel", method =requestmethod.post) PublicObject getallbyexcel (httpservletrequest request,httpservletresponse response, Modelmap model) {Map<string, object> resmap=NewHashmap<string, object>(); Multiparthttpservletrequest mulltipartrequest=(multiparthttpservletrequest) request; Map<string, multipartfile> filemap =Mulltipartrequest.getfilemap ();  for(Map.entry<string, multipartfile>Entity:fileMap.entrySet ()) {multipartfile Files=Entity.getvalue (); //multipartfile MF = entity.getvalue ();String path=request.getsession (). Getservletcontext (). Getrealpath ("/web-inf/res/upload"); String FileName=Files.getoriginalfilename (); Try{InputStream InputStream=Files.getinputstream (); byte[] B =New byte[1048576]; intLength =Inputstream.read (b); Path+= "\\" +FileName; //file stream writes to server sideFileOutputStream OutputStream =NewFileOutputStream (path); Outputstream.write (b,0, length);                Inputstream.close ();              Outputstream.close ();                                             } Catch(Exception e) {e.printstacktrace (); }        }                //multipartfile files=mulltipartrequest.getfile (null); //get the Upload server pathResmap.put ("MSG", "Entry Success"); returnResmap; }

Record-jquery uploadify File upload instance

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.