问题
I am trying to add attachments to JIRA issue using JIRA rest api. I am using mulesoft to develop this flow. But I am not able to figure out how to send a file using request connector in mule 4. JIRA only accepts file in the form of multipart content type.
I went through some of the documentation and it seems that till mule 3 using set attachment we can do this. In mule 4 dataweave is used to achieve this functionality but i am not able to find working code that can be used to implement this.
回答1:
From the HTTP Connector tests:
<http:request config-ref="requestConfig" path="/" method="POST">
<http:body><![CDATA[
#[
%dw 2.0
output multipart/form-data
---
{
parts : {
partOne : {
headers : {
"Content-Type": "text/plain",
"Custom" : "myHeader"
},
content : "content 1"
},
partTwo : {
headers : {
"Content-Disposition" : {
"name": "partTwo",
"filename": "a.html"
},
"Content-Type" : payload.^mimeType
},
content : payload
}
}
}]
]]></http:body>
</http:request>
This will send a two part message:
- The first named "partOne" with text/plain "content 1"
- The second named "partTwo" and filename "a.html" using the current payload
You can find more information on handling multipart content here.
来源:https://stackoverflow.com/questions/58475652/how-to-send-a-file-using-http-request-connector-in-mule4