Can any one tell me what is a the best way to convert a multipart file (org.springframework.web.multipart.MultipartFile) to File (java.io.File) ?
In my spring mvc w
small correction on @PetrosTsialiamanis post ,
new File( multipart.getOriginalFilename())
this will create file in server location where sometime you will face write permission issues for the user, its not always possible to give write permission to every user who perform action.
System.getProperty("java.io.tmpdir")
will create temp directory where your file will be created properly.
This way you are creating temp folder, where file gets created , later on you can delete file or temp folder.
public static File multipartToFile(MultipartFile multipart, String fileName) throws IllegalStateException, IOException {
File convFile = new File(System.getProperty("java.io.tmpdir")+"/"+fileName);
multipart.transferTo(convFile);
return convFile;
}
put this method in ur common utility and use it like for eg. Utility.multipartToFile(...)