Edit
这个问题不同于:jQuery Ajax 文件上传:所需的 MultipartFile 参数“文件”不存在 https://stackoverflow.com/q/29488852/2279082不同之处在于他们使用 jQuery 和 Ajax,而我使用 REST 客户端 - “Postman”
因此,我必须将其完全删除,而不是将 Content-Type 设置为 false。
另外,在搜索有关“Postman”的答案时,我相信人们会跳过其中包含 jQuery 和 Ajax 一词的问题,这就是发生在我身上的事情
End Edit
我在 Java8 上使用 Spring MVC Web 应用程序并在 tomcat7.x 上运行它。
春季版本是:4.2.6.RELEASE
javax servlet版本是:3.0.1
上下文.xml
...
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- max upload size in bytes -->
<property name="maxUploadSize" value="5242880" /> <!-- 5MB -->
<!-- max size of file in memory (in bytes) -->
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
</bean>
...
控制器.java
...
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(value = HttpStatus.CREATED)
public void importTranslations(@RequestParam (name = "myfile") MultipartFile myfile) {
myService.doSomething(myfile);
}
...
这是问题所在
我使用 Postman 发送 *.zip 文件。路径是正确的,一切看起来都不错,但是 spring 抛出异常:
“所需的 MultipartFile 参数‘myfile’不存在”
Here is the screenshot from Postman:
So the file is there and the key name is correct.
Everything seems OK, and yet, I get the error