How to send a file using http request connector in mule4

倖福魔咒の 提交于 2021-02-08 06:35:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!