Site icon NgDeveloper

How to convert multipart file to File in Spring Boot?

How-to-convert-multipart-file-to-file-spring-boot-featured
How-to-convert-multipart-file-to-file-spring-boot-blog

Whenever you are doing file upload functionality then you may need to come across this convertion stuff to convert from multipart file to file.

Converting Multipart File to File Code snippet:

private File convertMultiPartFileToFile(MultipartFile multipartFile) throws IOException {
File file = new File(multipartFile.getOriginalFilename());
FileOutputStream fos = new FileOutputStream(file);
fos.write(file.getBytes());
fos.close();
return file;
}

Do remember if you are planning to upload to any other REST API then you need to do this way,

new FileSystemResource(file);
Exit mobile version