简体   繁体   English

将JSON中的文件发送到Mule 3.8中的REST服务

[英]Send a file in JSON to REST service in Mule 3.8

I am working with Mule 3.8 and need to send a file to target REST service in json (base64). 我正在使用Mule 3.8,需要将文件发送到json(base64)中的目标REST服务。

I am trying to find options but any of them is not working. 我正在尝试找到选项,但是其中任何一个都不起作用。 I have a file in my payload or else I can read it from file. 我的有效负载中有一个文件,否则我可以从文件中读取它。

Here is my approach. 这是我的方法。 Generate JSON in Dataweave transformation using script and add the file content (transform to base64). 使用脚本在Dataweave转换中生成JSON并添加文件内容(转换为base64)。 This will give us JSON in required format. 这将为我们提供所需格式的JSON。 However we need to add file content in JSON too (sample JSON is below). 但是,我们也需要在JSON中添加文件内容(示例JSON在下面)。 We can get the file content using #[message.inboundAttachments['file'].dataSource.content] in payload, but not sure how to pass the same to dataweave. 我们可以在有效负载中使用#[message.inboundAttachments['file'].dataSource.content]获取文件内容,但不确定如何将其传递给dataweave。

> { "form_data": { "name": 'xyz' }, "files": [ { "fileid": "id1",
> "filedata": "base64 file data" }] }

(Posted solution on behalf of the OP) . (代表OP发布解决方案)

I used Custom java transformer and fetched all data from MuleMessage object. 我使用了自定义Java转换器,并从MuleMessage对象获取了所有数据。 Created json value and set it back in payload. 创建了json值,并将其设置回有效负载中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM