Try following code that copy uploaded input stream to file. You should make more checks (file exists, file created ...) and move this code to some helper class maybe. It uses org.apache.commons.io.IOUtils
from commons-io library.
if(multipartFile != null && multipartFile.getSize() > 0) {
// Upload to temp directory
File uploadFile = new File("/tmp/" + multipartFile.getOriginalFilename());
FileOutputStream fos = null;
try {
uploadFile.createNewFile();
fos = new FileOutputStream(uploadFile);
IOUtils.copy(multipartFile.getInputStream(), fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}