一、MockMultipartFile(org.springframework.mock.web.MockMultipartFile)
File file = new File("/Library/d7ca8dd1c3bebdf26a2c8f103cfbd901.jpg");
FileInputStream inputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(),
ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
二、commons-fileupload-1.3.2.jar
File file = new File(/Library/test.txt)
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem item=factory.createItem(file.getName(),"text/plain",true,file.getName());
MultipartFile multipartFile = new CommonsMultipartFile(item);
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/17451.html