Error background: Because the file is stored on a third party server, all need to speak will receive the Multipartfile file to convert to file and then transfer. (Spring MVC)
The following two methods were found through the search engine.
are declared in the spring XML. As follows:
<bean id= "Multipartresolver" class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
If you need to add the largest, minimum and other scope control, please own Baidu reference.
Method One: Strong turn
Method Two:
1 2 3 |
Commonsmultipartfile CF = (commonsmultipartfile) multfile; Diskfileitem fi = (Diskfileitem) cf.getfileitem (); File File = Fi.getstorelocation (); |
Parental test is effective. However, the problem with late discovery settings caused the file conversion to be incorrect and the file unreadable, causing the program to throw the is not a normal file exception.
Because of the randomness of the error, the option to use a buffer to implement this transformation is to use the Multipartfile.transferto () method with temporary files created in Java.
The code is as follows:
1 2 3 4 5 6 7 8 9 |
File f = null; try {f=file.createtempfile ("tmp", NULL); File.transferto (f);<br> f.deleteonexit (); catch (HttpException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} |
Parental test is effective.