一、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);

 

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!