openfeign调用文件服务的文件上传接口报错:Current request is not a multipart request

解决办法:

Api 接口

@Api(tags = "文件上接口")
@RestController
public class FileController {

    @Autowired
    private FileFeignService fileFeignService;

    @ApiOperation("上传文件")
    @PostMapping(value = "/uploadFile")
    public ResData<String> uploadFile(@RequestParam("file") MultipartFile file) {
        String url = fileFeignService.uploadFile(file);
        return ResData.ok(url);
    }


}

openfeign

@FeignClient("file-server")
public interface FileFeignService {

    @PostMapping(value = "file/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String uploadFile(@RequestPart("file") MultipartFile file);

}

文件服务

@RestController
@RequestMapping("/file")
public class FileController {
    @Autowired
    private OssServer ossServer;

    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadFile(@RequestPart("file") MultipartFile file) {
        return ossServer.uploadFile(file);

    }


}

openfeign调用文件服务的文件上传接口报错:Current request is not a multipart request_第1张图片

你可能感兴趣的:(Springcloud,spring,cloud)