Error background: Since the file is stored on a third-party server, all need to be told to convert the received Multipartfile file to files and then transfer. (Spring MVC)
The following two methods have been found through search engines.
are declared in the preceding spring XML. As follows:
<id= "Multipartresolver" class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver "/>
If you want to add the largest, minimum range control, please Baidu reference.
Method One: Strong turn
Method Two:
Commonsmultipartfile CF = (commonsmultipartfile) multfile; Diskfileitem fi = (Diskfileitem) cf.getfileitem (); File File = Fi.getstorelocation ();
The pro-test is effective. However, late-discovery Setup issues cause file conversion errors and the file is unreadable thereby causing the program to throw an is not a normal file exception.
because of the randomness of the error, choosing to use a buffer to implement the transformation is to use the temporary file created by Java Multipartfile.transferto () method.
The code is as follows:
File f = null;try { f=file.createtempfile ("tmp", null); File.transferto (f);
F.deleteonexit (); } catch (HttpException e) { e.printstacktrace ();} catch (IOException e) { e.printstacktrace ();}
The pro-test is effective.
On the problem of Multipartfile to file in Java data dump