多部分表单请求引发:不存在必需的MultipartFile参数'image' [英] Multipart form request throws: Required MultipartFile parameter 'image' is not present

查看:218
本文介绍了多部分表单请求引发:不存在必需的MultipartFile参数'image'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用邮递员将图像上传到服务器.我正在使用spring使其余的api如下:

I try to upload an image to a server using the postman. I am using spring to make the rest api as the followings:

  @RequestMapping(value = "/uploadPrescription", method =RequestMethod.POST)
  public  ResponseEntity<ResponseSuccessData> uploadPatientPrescription(
        @RequestBody  @RequestParam("image") MultipartFile image)
        throws  IOException {

但是它会引发错误:

      org.springframework.web.bind.MissingServletRequestParameterException: 
      Required MultipartFile parameter 'image' is not present

正如您在邮递员中看到的那样,键名是'image',而在REST API中,键名也是@RequestParam("image").

As you can see in the postman that key name is 'image' and in rest api is also @RequestParam("image").

以内容类型设置值-Content-type = multipart/form-data,boundaries ='-abc'

Setting value in content type - Content-type = multipart/form-data,boundaries='--abc'

这是我的多部分弹簧配置-

This is my spring config for multipart -

  @Bean
  public CommonsMultipartResolver multipartResolver() {

  CommonsMultipartResolver commonsMultipartResolver = new      CommonsMultipartResolver();
//commonsMultipartResolver.setMaxUploadSize(-1);
return commonsMultipartResolver;

}

可能是什么问题?

推荐答案

请删除标题部分

请删除邮递员标题中的-Content-Type:multipart/form-data; boundary ='abc'设置

Please remove the - Content-Type : multipart/form-data;boundary='abc' setting in the header part of postman

这篇关于多部分表单请求引发:不存在必需的MultipartFile参数'image'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆