简体   繁体   中英

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).

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). This will give us JSON in required format. However we need to add file content in JSON too (sample JSON is below). We can get the file content using #[message.inboundAttachments['file'].dataSource.content] in payload, but not sure how to pass the same to dataweave.

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

(Posted solution on behalf of the OP) .

I used Custom java transformer and fetched all data from MuleMessage object. Created json value and set it back in payload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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