Good moring or afternoon sir.
Today, I'm sharing you how to convert [File to MultiPartFile] in JAVA.
Trust Me! This is the code I'm actually using in my system :)
1. You can use CommonsMultipartFile
An example of a filePath is shown below.
ex) C:/Users/han/test.xlsx
File yourFile = new File(filePath);
DiskFileItem fileItem = new DiskFileItem("file", Files.probeContentType(yourFile.toPath()), false, yourFile.getName(), (int) yourFile.length() , yourFile.getParentFile());
InputStream input = new FileInputStream(yourFile);
OutputStream os = fileItem.getOutputStream();
IOUtils.copy(input, os);
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
I hope this is the result you want.
If it's not working or if you have any questions, please leave a comment.
Have a nice day!