Postman - 所需的 MultipartFile 参数不存在 - Spring、Java
Postman - Required MultipartFile parameter is not present - Spring, Java
编辑
这个问题不同于:
区别在于他们使用 jQuery 和 Ajax,而我使用 REST 客户端 - 'Postman'
因此,我不得不将其完全删除,而不是将 Content-Type 设置为 false。
另外,在搜索关于'Postman'的答案时,我相信人们会跳过其中包含jQuery和Ajax字样的问题,这就是我遇到的情况
结束编辑
我在 Java8 上使用 Spring MVC 网络应用程序,在 tomcat7.x 上使用 运行 MVC 网络应用程序。
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 抛出异常:
"Required MultipartFile parameter 'myfile' is not present"
这是来自 Postman 的截图:
所以文件在那里并且键名是正确的。
一切似乎都很好,但是,我得到了错误
在 Whosebug 中大量搜索后,我发现了这个问题:jQuery Ajax file upload : Required MultipartFile parameter 'file' is not present
我尝试将 Postman 中的 Content-Type header 设置为 false,但出现错误。
当我删除 Content-Type header 时,它起作用了!!
希望这对某人有所帮助
编辑
这个问题不同于:
因此,我不得不将其完全删除,而不是将 Content-Type 设置为 false。
另外,在搜索关于'Postman'的答案时,我相信人们会跳过其中包含jQuery和Ajax字样的问题,这就是我遇到的情况
结束编辑
我在 Java8 上使用 Spring MVC 网络应用程序,在 tomcat7.x 上使用 运行 MVC 网络应用程序。
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 抛出异常: "Required MultipartFile parameter 'myfile' is not present"
这是来自 Postman 的截图:
在 Whosebug 中大量搜索后,我发现了这个问题:jQuery Ajax file upload : Required MultipartFile parameter 'file' is not present
我尝试将 Postman 中的 Content-Type header 设置为 false,但出现错误。 当我删除 Content-Type header 时,它起作用了!!
希望这对某人有所帮助