Postman - Required MultipartFile parameter is not present - Spring, Java(Postman - 所需的 MultipartFile 参数不存在 - Spring,Java)
问题描述
Edit
This question is different from: jQuery Ajax file upload : Required MultipartFile parameter 'file' is not present The difference is that they use jQuery and Ajax, while I use a REST client - 'Postman'
So instead of setting Content-Type to false, I had to remove it altogether.
Also, when searching for answers about 'Postman', I believe people will skip questions that have the words jQuery and Ajax in them, this is what happened to me
End Edit
I'm using Spring MVC web application on Java8 and running it on tomcat7.x.
Spring version is: 4.2.6.RELEASE
and javax servlet version is: 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);
}
...
Here is the issue
I use Postman to send a *.zip file. The path is correct and everything looks good, but spring throws an exception: "Required MultipartFile parameter 'myfile' is not present"
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
After a lot of searching here in stackoverflow, I found this question: jQuery Ajax file upload : Required MultipartFile parameter 'file' is not present
I tried setting the Content-Type header in Postman to false and got an error. When I removed the Content-Type header, it worked!!
Hope this helps someone
这篇关于Postman - 所需的 MultipartFile 参数不存在 - Spring,Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Postman - 所需的 MultipartFile 参数不存在 - Spring,Java
基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01