The service structure is very simple, and consumers call the service of the service provider through Feign.
The provider has a file upload function. According to the interface document, the parameter type is File, which is placed in parallel with other parameters.

Key points: 1. Use @RequestPart annotations for File parameters at the routing layer; 2. Add consumes = MediaType.MULTIPART_FORM_DATA_VALUE instructions at the interface layer.

  1. Routing layer

     @PostMapping(value = "/notify/upload")
     @ApiOperation("上传通知音")
     public String upload (
             AudioRecordScooperReq audioRecordScooperReq,
             @RequestPart("file") MultipartFile file) {
    
         audioRecordScooperReq.setToken(tokenValue);
         return audioRecordFeign.upload(audioRecordScooperReq, file);
     }
  2. Feign interface layer

     // 上传通知音 -
     @PostMapping(value = "/scooper-record/data/notify/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
     String upload(@SpringQueryMap AudioRecordScooperReq audioRecordScooperReq,
                   @RequestBody() MultipartFile file);

yizheng
301 声望27 粉丝

一蓑烟雨任平生