Spring boot将收到的MultiPartFile转发到Feign Client

问题描述 投票:0回答:1

是否有可能将接收到的MultiPartFile项从REST资源转发到Feign Client,并期望它能正常工作?

我处于这种情况下,我需要通过微服务中的API网关从客户端获取MultiPartFile请求,然后将其传递给外部服务,并且在获得外部服务的响应之后,需要在主服务中做一些额外的工作中间微服务并响应客户端。

微服务REST API:

@RestController
@RequestMapping("/api")
public class VisionApiTestResource {

    ....

    @PostMapping("/vision-test/upload-image")
    public ResponseEntity<VisionApiTestResultDTO> handleFileUpload(@RequestParam("file") MultipartFile file ) {
        VisionApiTestResultDTO visionApiTestResultDTO = visionApiTestService.testVisionApi(file);
        return ResponseEntity.ok().body(visionApiTestResultDTO);
    }

    ....

}

正在调用假客户端的服务


@Service
public class VisionApiTestService {

    ...

    public VisionApiTestResultDTO testVisionApi(MultipartFile multipartFile) {

        BackgroundRemoverResultDTO backgroundRemoverResultDTO = backgroundRemoverClient.removeBackground(multipartFile);

        ...
    }

}

我的假客户:

@FeignClient(name = "BackgroundRemover", url = "http://localhost:8000")
public interface BackgroundRemoverClient {

    @RequestMapping(value = "/background_removal/remove_background/", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    BackgroundRemoverResultDTO removeBackground(@RequestPart("file") MultipartFile untouchedImageFile);

}

这是我得到的例外:

java.lang.IllegalArgumentException: Illegal base64 character 3a
        at java.util.Base64$Decoder.decode0(Base64.java:714)
        at java.util.Base64$Decoder.decode(Base64.java:526)
        at java.util.Base64$Decoder.decode(Base64.java:549)
        at com.whereandshare.kiosk.kioskservice.service.VisionApiTestService.testVisionApi(VisionApiTestService.java:37)
        at com.whereandshare.kiosk.kioskservice.service.VisionApiTestService$$FastClassBySpringCGLIB$$193667fb.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769)
spring multipart spring-cloud-feign feign
1个回答
0
投票

实际上,没有Problom转发伪装客户端从Spring Boot REST端点接收到的MultiPartFile。

并且打印的堆栈跟踪与假装和弹簧无关。从假装获得结果后,我犯了一个小小的愚蠢的错误。

© www.soinside.com 2019 - 2024. All rights reserved.