【发布时间】:2017-01-07 16:58:59
【问题描述】:
编辑
这个问题不同于:jQuery Ajax file upload : Required MultipartFile parameter 'file' is not present 不同之处在于他们使用 jQuery 和 Ajax,而我使用的是 REST 客户端 - 'Postman'
因此,我不得不将其完全删除,而不是将 Content-Type 设置为 false。
另外,在搜索“Postman”的答案时,我相信人们会跳过其中包含 jQuery 和 Ajax 的问题,这就是发生在我身上的事情
结束编辑
我在 Java8 上使用 Spring MVC Web 应用程序并在 tomcat7.x 上运行它。
Spring 版本为:4.2.6.RELEASE,javax servlet 版本为:3.0.1
context.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>
...
controller.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' 不存在"
【问题讨论】:
-
@Jens - 请参阅我在问题开头的编辑,关于可能的重复。我花了一段时间才找到答案,这是因为我搜索了 Postman 并忽略了有关 jQuery 和 Ajax 的答案
标签: java spring tomcat multipartform-data postman