Use the ElementUI to implement the image to the local example

See Hungry? Official documentation can understand how to use upload components. Http://element.eleme.io/#/zh-cn/component/upload

The page code for the front desk is:

     uploaded to the server     
Specific method of bound Method Upload the official document

Upload to the local, you need to establish an interface in the background for receiving, the interface code is as follows:

@Overridepublic void handle (List fileItemList, NetUpMediaapiImgUpload up, NetDownMediaapiImgUpload down, HttpServletResponse response) {System.out.println ( “path:” + getBasePath ()); if {List
 paths (CommUtil.isEmpityList (fileItemList)!) = new arraylist (); for (FileItem fileItem: fileitemlist) {string path = writefile (fileItem); paths.add ("../../ static / img /" + fileItem.getname ()); // Browser The absolute path is not allowed to use the absolute path logger.info ("upload success:" + PATH); logger.info ( "Update Data");} down.setAllPath (paths);}} public static String writeFile (FileItem file) {String fileName = getFileName (file.getName ()); fileName = formatFileName (fileName); fileName = getFilePrefix ( FileName) + '.' + getFilesuffix (filename); string path = getBasePath () + "/ xmob-web / static / img /"; // path = "E: \\ xmob \\ trunk \\ xmob-web \ \ static \\ img \\; // The picture should be placed in the Static directory of the web folder, File Desfile = New File (PATH); if (! Desfile .Exists () &&! Desfile .Isdirectory ()) {System. Out.println ("// does not exist"); desfile.mkdir ();} string result = null; try {inputstream in = file.getinputStream (); fileoutputstream out = new fileoutputstream (Path + "/" + filename); / / Create a buffer BYTE BUFFER [] = new byte [1024]; / ​​/ Determine whether the data in the input stream has been read in the identifier INT LEN = 0; // Cycle the input stream into the buffer, (LEN = IN.READ (BUffer)> 0 means in IN also there is data while ((len = in.read (buffer))> 0) {// Use the FileoutPutStream output stream to write the data of the buffer to the specified directory (PATH) OUT .write (buffer, 0, len);} in.close (); out.close (); // Delete the provisional file file.delete () () () (); result = path + "/" + filename;} Catch (Exception E) {E.PrintStackTrace ();} Return Result;} / ** * Get resource path * @return * / private static string getBasePath () {string template_dir = system.getProperty ("user.dir"); Return template_dir.substring (0, template_dir.lastindexof (file.separator));} / ** * Note: Different browser submitted file names, some browser submitted file names are path , Such as: c: \ a \ b \ 1.txt, and some is just a simple file name, such as: 1.Txt * Process the path part of the file name of the acquired upload file, only keep the file name part * @Param filename * @return * / private static string getFileName (String filename) {filename = filename.substring (filename.lastindexof (file.separATOR) +1); Return FileName;} / ** * Formatted file name * @Param filename * @return * / private static string formatFileName (String filename) {string [] SARR = filename.split ("\\." ); String str = SARR [0]; str = str.replaceAll ("," "); str = str.replaceall (" \\ s + | _ "," - "); string result = str +". "+ SARR [1]; Return Result;} / ** * Get file name prefix * / private static string getFilePrefix (String filename) {filename = formatFileName (filename); string [] SARR = filename.split ("\\.") RETURN SARR [0];} / ** * Get file name suffix * / private static string getFilesuffix (String filename) {filename = formatFileName (filename); string [] SARR = filename.split ("\\)); Return Sarr [1];}   The above example of using the Elementui to upload the picture to the local, which is the full content of Xiaobian sharing to everyone, I hope to give you A reference, I also hope that you will support TUMI clouds.                     
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment