SpringMVC 提示:HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=解析

虾米哥 阅读:258 2021-03-31 16:53:30 评论:0

今天在编写文件上传模块时,使用postman 上传文件测试相关功能时,提示如下错误信息:

"timestamp": 1473349676109, 
  "status": 415, 
  "error": "Unsupported Media Type", 
  "exception": "org.springframework.web.HttpMediaTypeNotSupportedException", 
  "message": "Content type 'multipart/form-data;boundary=----WebKitFormBoundaryTVc9eDC2a2elulOx;charset=UTF-8' not supported", 
  "path": "/upload"

错误代码:

@ApiOperation(httpMethod = "POST", value = "文件上传") 
	@RequestMapping(value = "/fileUpload", method = { RequestMethod.POST }) 
	@ResponseBody 
	public Result upload( 
			@RequestBody @ApiParam(name = "上传对象", value = "json格式对象", required = true) ChunkInfoModel entity) { 
		if(logger.isDebugEnabled()){ 
			logger.debug(entity.toString()); 
		} 
		EfileInfo model = upload.smallFileUpload(entity); 
		return Result.ok("文件上传成功").setDatas("model", model); 
	}

正确代码:

    @RequestMapping(value = "/fileUpload", method = { RequestMethod.POST }) 
	@ResponseBody 
	@ApiOperation(httpMethod = "POST", value = "文件上传") 
	public Result upload(ChunkInfoModel entity) { 
		if (logger.isDebugEnabled()) { 
			logger.debug(entity.toString()); 
		} 
		EfileInfo model = upload.smallAttachUpload(entity); 
		 
		return Result.ok("文件上传成功").setDatas("model", model); 
	}

解决方案:

去掉 @RequestBody 注解就行了

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
排行榜
KIKK导航

KIKK导航

关注我们