java.lang.NullPointerException while creating DiskFileItem

前端 未结 5 1634
我寻月下人不归
我寻月下人不归 2021-01-13 04:14

I am trying to write a unit test for handling a file upload controller using Spring 3. Now if I send the image over to my service method through the controller everything wo

5条回答
  •  半阙折子戏
    2021-01-13 05:10

    And if none of the solutions above work for you as it happened for me :) simply ditch the DiskFileItem and use the solution bellow:

      final File fileToUpload = new File("src/test/resources/files/test.txt");
      final MultiValueMap request = new LinkedMultiValueMap();
      request.add("file", new FileSystemResource(fileToUpload.getAbsolutePath()));
    

提交回复
热议问题