FileUploadException: the request was rejected because no multipart boundary was found
概述
最近在做一个视频检测的需要,使用Postman上传视频时,代码抛错:
ERROR 13557 [] [http-nio-5000-exec-8] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found] with root cause
org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.init(FileItemIteratorImpl.java:178)
背景
业务应用层的文件上传Controller:
@Resource
private FileService fileService;
@PostMapping(value = "video")
@ApiOperation(value = "提交视频识别", httpMethod = "POST")
public Result video(@RequestParam("file") MultipartFile file, @LoginUser SysUser user, HttpServletRequest request) {
Result<FileInfo> fileInfoResult = fileService.fileUpload(ArmConstant.BUCKET, file);
}
上面代码里面的FileService是基于FeignClient而定义的接口:
@FeignClient(name = ServiceNameConstants.FILE_SERVICE, fallbackFactory = FileServiceFallbackFactory.class, decode404 = true)
public interface FileService {
@PostMapping(value = "/upload/{bucket}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Result<FileInfo> fileUpload(@PathVariable("bucket") String bucket, @RequestParam("file") MultipartFile file);
}
FileService需要有一个支撑的服务,即file-center
服务,其Controller定义如下:
@RestController
@Slf4j
public class FileController {
@PostMapping("/upload/{bucket}")
public Result<FileInfo> fileUpload(@PathVariable("bucket") String bucket, @RequestParam("file") MultipartFile file) {
}
}
分析
全网百度以及Google搜索,几户全部都在讲如何设置Postman,一度让我质疑Postman的问题,或者是我使用Postman的问题。网上搜索时,一定要带着自己的批判思维分析,狠多文章都是瞎搬来乱抄去。再者,作为一款成熟的自动化接口测试工具,Postman几乎不会被你我发现bug。
但是,Postman的使用我可是滚瓜烂熟。且事实上,Postman配置也没任何问题:
搁置一晚上。
实在无法,全局搜索MultipartFile file
:
突然发现有点东西,@RequestPart和@RequestParam有何区别?
此时正好发现巨坑
把三个地方的@RequestParam替换成@RequestPart解决问题;
不得不说,Feign这玩意的坑,真不少。但是在Feign-GitHub搜不到FileUploadException: the request was rejected because no multipart boundary was found
任何相关信息。
Feign的坑,参考我的另一篇blogFallbackFactory使用
延伸
@RequestPart和@RequestParam有何区别?
另写一篇@RequestParam和@RequestPart区别及Feign踩坑
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix