Apache camel Camel Exchange getbody的文件对象为空

Apache camel Camel Exchange getbody的文件对象为空,apache-camel,apache-httpcomponents,Apache Camel,Apache Httpcomponents,在我的骆驼路线中,我试图获取文件对象 rest("/file") .post("/extract") .to("direct:extract"); from("direct:extract") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { File file =

在我的骆驼路线中,我试图获取文件对象

rest("/file")
    .post("/extract")
    .to("direct:extract");
    from("direct:extract")
    .process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
             File file = exchange.getIn().getBody(File.class);
             LOG.info("file : "+file);
     multipartEntityBuilder.addPart("file", new FileBody(file, ContentType.MULTIPART_FORM_DATA,filename));

        }
        })
在这里,我从rest发送文件,在处理器中,当我试图通过ExchangeGetBody时,我得到的是空值。 但如果我尝试获取Inputstream和byte[],这意味着它工作正常

    byte[] bytes = exchange.getIn().getBody(byte[].class);
    LOG.info("bytes : "+bytes);
    InputStream is = exchange.getIn().getBody(InputStream.class);

我的目标是从exchange getBody获取文件对象,如果有任何错误,请告诉我。

没有
java.io.file
作为消息体,因为HTTP文件上载不是表示为
java.io.file
,而是表示为输入流。
java.io.File
用于Camel中的常规文件组件

.produces(MediaType.APPLICATION_JSON)
    .consumes(MediaType.MULTIPART_FORM_DATA)
   .to("direct:extract");

    from("direct:extract")

    .setBody().simple("${body}")
    .to("http4://....")
    .end();

您不需要将其转换为Byte[]或inputstream,您可以直接将其作为正文传递,然后将其设置为正文

谢谢,我将尝试使用inputstream。我也尝试过使用inputstream,但无法获得响应,我从POST发送文件,就像上面的代码一样,因为我没有获得file object/inputstream/bytes[],如果我通过路径发送文件,比如:-from(“file:E:/folder4/pdfReceipt?noop=true”),我可以得到响应。现在我可以使用byte[]格式上传pdf、txt文件,但相同的代码不适用于图像文件(.jpg、.png),无法上载图像文件。当您使用图像与其他类型的文件时,能否检查HTTP头的内容类型是否设置为正确的类型。感谢您的帮助,我尝试将多部分/表单数据作为所有类型文件的消费(多部分/表单数据)及其工作方式。