SpringBoot--""Required request part 'file' is not present""


今天做图片上传的功能,做好之后进行测试,一直提示“"Required request part 'file' is not present"”

在网上找各种方式,有的说配置文件,有的说别用自带的文件解析类MultipartFileResolver都没有解决我的问题。

后来仔细看发送的请求

复制代码
------WebKitFormBoundaryFlaeSM38XP7nFtBi
Content-Disposition: form-data; name="fileUpload"; filename="bb.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryFlaeSM38XP7nFtBi--
注意:这里是name="fileUpload",我用的Advanced Rest Client模拟发送http请求,它把名字设置成了这个,而我的controller是
@PostMapping("image")
    public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file){
        System.out.println("请求到来" + file.getName());
        return ResponseEntity.ok(uploadService.uploadImage(file));
    }

两边的文件名称不对应,导致这个问题,所以controller的

@RequestParam("file") 改为@RequestParam("fileUpload")就OK!
复制代码

转载于:https://www.cnblogs.com/runwithraining/p/12114373.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM