作者简介:大家好,我是smart哥,前中兴通讯、美团架构师,现某互联网公司CTO
联系qq:184480602,加我进群,大家一起学习,一起进步,一起对抗互联网寒冬
学习必须往深处挖,挖的越深,基础越扎实!
rest服处理文件上传
现在的文件上传服务基本上都是先上传,后提交路径
测试用例
@Test
public void whenFileUploadSuccess() throws Exception {
// v5.0+ fileUpLoad方法已经过时了
String file = mockMvc.perform(multipart("/file")
.file(new MockMultipartFile("file", "test.txt", "multipart/form-data", "hello upload".getBytes())))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
System.out.println(file);
}
输出
{"absolutePath":"G:\\dev\\project\\mrcode\\example\\imoo