文件到MultipartFile引发NullPointerException

时间:2018-10-02 11:19:32

标签: java file spring-boot file-upload multipart

Commons-fileupload

    <!-- File Upload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.3</version>
    </dependency>

我正在尝试将文件转换为MultipartFile

 Line#1 ) File file = new File("C:\\Users\\Foo\\AppData\\Local\\Temp\\ErrorFile-1538475847143.csv");
 Line#2 ) FileItem fileItem = new DiskFileItem("file", "text/csv", false, file.getName(), (int) file.length(), file.getParentFile());
 Line#3 ) MultipartFile multipartFile = new CommonsMultipartFile(fileItem);

但是Line#2抛出异常

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.commons.fileupload.disk.DiskFileItem.toString()

任何解决方案?

1 个答案:

答案 0 :(得分:0)

这解决了我的问题:

uint32_t