Reputation: 65
I am trying to get information of attached file in mule application.I am using POSTMAN to POST a text file .But After HTTP receiver in mule application Inbound Attachment Names have size=0.How to resolve such scenario?
Upvotes: 1
Views: 4775
Reputation: 5938
Sender:
<http:listener config-ref="HTTP_Listener_Configuration" path="apptest" doc:name="HTTP"/>
<set-attachment attachmentName="test.json" value="{'Hi':'Hello'}" contentType="text/plain" doc:name="Attachment-JSON"/>
<set-attachment attachmentName="inputdata.json" value="{'k1':'v1','k2':'v2'}" contentType="text/plain" doc:name="Attachment"/>
<set-payload value="#['some data']" doc:name="Set Payload"/>
<http:request config-ref="HTTP_Request_Configuration" path="path2" method="POST" doc:name="HTTP"/>
Receiver:
<http:listener config-ref="HTTP_Listener_Configuration" path="path2" allowedMethods="POST" doc:name="HTTP"/>
<foreach collection="#[message.inboundAttachments]" doc:name="For Each">
<set-payload value="#[payload.getInputStream()]" doc:name="Set Payload"/>
<logger message="File Name: #[key] Payload is: #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</foreach>
Upvotes: 1
Reputation: 329
Check this link:
Tool for sending multipart/form-data request
You basically need to select form-data and select File from the drop down then upload the file using the Choose Files button.
You can check the attachment in mule using the mel expression:
'#[message.inboundAttachments]
Here is my updated answer this I can now post a photo:
1.
OR
'#[org.apache.commons.io.IOUtils.toByteArray(payload.getInputStream());]
'#[payload]
The result in my console is like this (I removed others):
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:file="http://www.mulesoft.org/schema/mule/file" .. .. .. .. <mule xmlns:context="http://www.springframework.org/schema/context" xmlns:cluster="http://www.mulesoft.org/schema/mule/ee/cluster" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" .. .. .. ..
Upvotes: 2
Reputation: 2835
I tested Postman sending binary data from a file upload and it seems like it sends the file contents in the request body, which means you will get that in the payload, not as inbound attachments. In order to have the file as an inbound attachment you should POST form-data with Postman so that a multipart request is sent, as mentioned by @Ralph. I've checked and that way it works. HTH.
Upvotes: 0