Charu Khurana
Charu Khurana

Reputation: 4551

How to write a file object to outbound endpoint in Mule

I have a <file:inbound-endpoint> which reads a large file and pass it to a java component which splits large file into multiple smaller files. I add all these smaller files into a list and return list from java component into mule flow.

Now, in mule flow, I am using <collection-splitter> or <foreach> to output those files to the <file:outbound-endpoint>.

The problem is that

Upvotes: 1

Views: 4481

Answers (2)

Charu Khurana
Charu Khurana

Reputation: 4551

or 1st I did as @David suggested to add file:file-to-byte-array-transformer.

For 2nd part, to get the name of file outputting to <file:outbound-endpoint> same as the file name assigned while creating file, I did following:

    <foreach>
        <set-variable variableName="fname" value="#[payload.path]"/>
        <logger level="INFO" message="fname is: #[fname]" />
        <file:file-to-byte-array-transformer />  
        <file:outbound-endpoint path="${file.csv.path}" outputPattern="#[fname]"/> 
    </foreach>

Before converting file to byte array, get the file name as after byte array conversion, its not available in #[payload] though you may still get it from #[originalPayload]

Upvotes: 3

David Dossot
David Dossot

Reputation: 33413

  • You need to add a file:file-to-byte-array-transformer after you've split the List<File> and before file:outbound-endpoint so Mule will read the actual content of the java.io.File.
  • You need to define an outputPattern on the file:outbound-endpoint, using a MEL expression to construct a unique file name based on the properties of the in-flight message and also on other expressions, like timestamp or a UUID, whatever fits your needs.

Upvotes: 4

Related Questions