apache-camel - Camel Exchange getbody 的文件对象为空
问题描述
在我的骆驼路线中,我试图获取文件对象。
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));
}
})
从休息开始,我在处理器中发送文件,当我试图通过交换 getBody 时,我得到了空值。但是如果我尝试获取 Inputstream 并且 byte[] 意味着它工作正常,那么同样的事情。
byte[] bytes = exchange.getIn().getBody(byte[].class);
LOG.info("bytes : "+bytes);
InputStream is = exchange.getIn().getBody(InputStream.class);
我的目标是从交换 getBody 获取文件对象,有什么问题请告诉我。
解决方案
.produces(MediaType.APPLICATION_JSON)
.consumes(MediaType.MULTIPART_FORM_DATA)
.to("direct:extract");
from("direct:extract")
.setBody().simple("${body}")
.to("http4://....")
.end();
不需要转换成Byte[]或者inputstream,直接作为body传递,然后设置为body
推荐阅读
- git - 如何使用 android studio 删除我在 gitlab 上的最后一次推送
- node.js - 做一个从 nodejs 到 oracle 数据库的测试连接
- r - 通过R中的方式替换一些行数据
- python - 如何点击 selenium 从 expedia 返回的第一个搜索结果
- node.js - 在Nodejs中逐年,逐月和逐日获取Logger
- google-apps-script - ReferenceError:未定义 YouTube/将 YouTube 评论插入电子表格
- apache-superset - 超集数据集查询
- node.js - 为什么我在开始使用 React 时遇到错误?
- php - 如何在没有 html 标签的情况下获取 wordpress 页面内容?
- php - 如何使用 guzzle promise 提高响应时间?