Patrick Deruyter
Patrick Deruyter

Reputation: 21

Mule File Inbound to HTTP Outbound

I have a case where I need to poll a directory on my file system. Each file that is added to that directory needs to be posted to an HTTP endpoint.

The HTTP endpoint is available on "/rest/latest/file". Using postman, I've verified that the REST call works with the following settings:

My mule flow currently looks like this:

<file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" moveToPattern="#[message.inboundProperties['originalFilename']].backup" moveToDirectory="src/main/resources/output" doc:name="File"/>
<flow name="importdataqualityresultsFlow1" doc:name="importdataqualityresultsFlow1">
    <file:inbound-endpoint path="src/main/resources/input" responseTimeout="10000" doc:name="File"/>
    <set-payload value="#[['file' :#[message.inboundAttachments['text.txt']]]]" doc:name="Set Payload"/>
    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="80" path="rest/latest/file" method="POST" user="Admin" password="admin" contentType="application/form-data" doc:name="HTTP"/>
</flow>

I can tell in my application logs that the user logs in using basic auth, after which I get a stack trace.

Any help / pointers would be greatly appreciated.

Upvotes: 1

Views: 413

Answers (1)

David Dossot
David Dossot

Reputation: 33413

You need to create a map payload with the form fields:

<flow name="importdataqualityresultsFlow1">
  <file:inbound-endpoint path="src/main/resources/input" />
  <object-to-string-transformer />
  <set-payload value="#[['file': message.payload]]" />
  <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="80" path="rest/latest/file" method="POST" user="Admin" password="admin" contentType="application/form-data" />
</flow>

Upvotes: 2

Related Questions