Jersey 客户端使用 Reactive 库发布多部分请求,不适用于 Micronaut 服务器端休息服务

我需要使用 Rest Client 将 2GB 文件上传到服务器端 Rest 服务。 客户端是采用 Multipart 反应方式的 Jersey 客户端。

Jersey 反应式客户端中的示例其余客户端代码


Client client = ClientBuilder.newClient();
client.register(RxFlowableInvokerProvider.class);

MultiPart multipart = new Multipart("file",new File("abc.zip"));
 
Flowable<Response> responseFlowable =
        client.target("http://aaaaa.org/upload")
              .request()
              .rx(RxFlowableInvoker.class)
              .post(multipart,multipart.getMediaType());
 
String responseString = responseFlowable.blockingFirst();

服务端休息服务由micronaut开发。

@Post(value =  "/upload",consumes = MediaType.MULTIPART_FORM_DATA,produces = MediaType.TEXT_PLAIN)
    Single<String> go(@Body MultipartBody multipartBody) {
        return Single.create(emitter -> {
            multipartBody.subscribe(new Subscriber<CompletedPart>() {
                private Subscription s;
                List<String> datas = new ArrayList<>();
                @Override
                public void onSubscribe(Subscription s) {
                    this.s = s;
                    s.request(1);
                }

                @Override
                public void onNext(CompletedPart data) {
                    try {
                        if(data instanceof CompletedFileUpload) {
                            datas.add(new String(data.getBytes(),StandardCharsets.UTF_8));
                        } else {
                           // Instance of CompletedPart. Metadata values
                           String key = data.getKey();
                        }
                        s.request(1);
                    } catch (IOException e) {
                        s.cancel();
                        emitter.onError(e);
                    }
                }

                @Override
                public void onError(Throwable t) {
                    emitter.onError(t);
                }

                @Override
                public void onComplete() {
                    emitter.onSuccess(String.join("|",datas));
                }
            });
        });
    }

客户端能够向服务器发送文件元数据信息,如文件名、大小、边界信息,但不能发送多部分数据(2 GB 文件)。你能告诉我为什么使用多部分的文件数据没有被发送到服务器

GlacierZ 回答:Jersey 客户端使用 Reactive 库发布多部分请求,不适用于 Micronaut 服务器端休息服务

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/72120.html

大家都在问