Multipartfile与File类型相互转换
转⾃:
// M转F
File file = new File(path);
// F转M
File file = new File("src/test/");
FileInputStream input = new FileInputStream(file);
// ⽂本⽂件
MultipartFile multipartFile =
new Name(), Name(), "text/plain", input );
/
/ 图⽚⽂件
MultipartFile multipartFile = new Name(),Name(),"image/jpeg", input ); // 源码
/**
* Create a new MockMultipartFile with the given content.
* @param name the name of the file
* @param originalFilename the original filename (as on the client's machine)
* @param contentType the content type (if known)
* @param contentStream the content of the file as stream
inputtypefile样式* @throws IOException if reading from the stream failed
*/
public MockMultipartFile(
String name, @Nullable String originalFilename,
@Nullable String contentType, InputStream contentStream)
throws IOException {
this(name, originalFilename, contentType, pyToByteArray(contentStream));
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。