I want to convert a file to multipartfile using spring. I have done this:
File in; MultipartFile file = null; in = new File("C:...file on disk"); int size = (int) in.length(); DiskFileItem fileItem = new DiskFileItem("file", "application/vnd.ms-excel", false, nomefile, size ,in.getAbsoluteFile()); file = new CommonsMultipartFile(fileItem);
but get this exception:
threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException at org.apache.commons.fileupload.disk.DiskFileItem.getSize(DiskFileItem.java:316)
I think fileItem is null, but is there another solution in debug mode? I have this post Convert File to MultiPartFile , but it does not work and has no solution.
source share