zoukankan      html  css  js  c++  java
  • 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!
    
    
  • 相关阅读:
    1175_UPDATE报错[转]
    python&sql
    MySQL安装
    python[1]
    一道题理解层次分析法【转】
    神经网络编程入门
    监督学习和无监督学习
    ML-3Normal equation
    ML_note1
    CTF之隐写总结
  • 原文地址:https://www.cnblogs.com/runwithraining/p/12114373.html
Copyright © 2011-2022 走看看