[英]Error message = Required MultipartFile parameter 'file' is not present
Testing a spring file upload form, the controlelr signature looks like this 测试一个spring文件上传表单,controlelr签名看起来像这样
@RequestMapping(value = "upload", method = RequestMethod.POST)
@ResponseBody
public void upload(@RequestParam("file") MultipartFile multipartFile) {}
and the test this 并测试这个
final MockMultipartFile file
= new MockMultipartFile("content", "myFile.txt", "text/plain", "hello".getBytes());
MockHttpServletRequestBuilder mockHttpServletRequestBuilder =
.fileUpload("/upload/")
.file(file)
.accept(MediaType.APPLICATION_JSON);
but I get the aforementioned : Error message = Required MultipartFile parameter 'file' is not present 但我得到上述内容: 错误消息=必需的MultipartFile参数'file'不存在
You named the parameter as "file" and not as "content": 您将参数命名为“file”而不是“content”:
Change: 更改:
new MockMultipartFile("content", "myFile.txt", "text/plain", "hello".getBytes());
To: 至:
new MockMultipartFile("file", "myFile.txt", "text/plain", "hello".getBytes());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.