feign接口调用服务上传图片 报错 the request was rejected because no multipart boundary was found

在用postman 请求这个调用接口的时候,报了the request was rejected because no multipart boundary was found

1.首先检查是否导入了下面两个包

<dependency>
        <groupId>io.github.openfeign.form</groupId>
        <artifactId>feign-form</artifactId>
        <version>3.2.2</version>
    </dependency>
    <dependency>
        <groupId>io.github.openfeign.form</groupId>
        <artifactId>feign-form-spring</artifactId>
        <version>3.2.2</version>
    </dependency>

2.再检查一下feign接口是否有如下参数

	/**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);

重点

请求体必须是@RequestPart这个注解,
并且consumes=MediaType.MULTIPART_FORM_DATA_VALUE

原因

因为源码里面content-type会被",“或”;"进行转换为Map,在org.apache.tomcat.util.http.fileupload.FileUploadBase.FileItemIteratorImpl#FileItemIteratorImpl抛出异常,所以大家一定要注意jar包版本问题。

上一篇:SpringBoot项目上传文件报错:the request was rejected because its size (53030696) exceeds the configured maxim


下一篇:springmvc:文件的上传与下载