Skip to content

Instantly share code, notes, and snippets.

@zarulizham
Last active June 22, 2020 01:32
Show Gist options
  • Save zarulizham/9fbd43ce546565b3430c9fe8fc5e6e71 to your computer and use it in GitHub Desktop.
Save zarulizham/9fbd43ce546565b3430c9fe8fc5e6e71 to your computer and use it in GitHub Desktop.
WSO2 API Multipart Content Type. Attach String or attachments and store to the WSO2 filesystem.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/multi" name="MultipartAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data" />
<property name="attachment_base64" expression="//mediate/attachment"></property>
<property name="attachment_filename" expression="//mediate/attachment/@filename"></property>
<log level="custom">
<property name="full_name" expression="//mediate/full_name/text()"></property>
<property name="attachment_filename" expression="//mediate/attachment/@filename"></property>
<!--<property name="attachment_base64" expression="//mediate/attachment"></property>-->
</log>
<payloadFactory media-type="xml">
<format>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:binary>
</format>
<args>
<arg evaluator="xml" expression="$ctx:attachment_base64" />
</args>
</payloadFactory>
<script language="js">
<![CDATA[
var binaryNode = mc.getEnvelope().getBody().getFirstElement().getFirstOMChild();
binaryNode.setBinary(true);
]]>
</script>
<property name="transport.vfs.ReplyFileName" expression="$ctx:attachment_filename" scope="transport" />
<property name="transport.vfs.Streaming" value="true" scope="transport" />
<property name="OUT_ONLY" value="true" />
<property name="ClientApiNonBlocking" action="remove" scope="axis2" />
<property name="messageType" value="application/binary" scope="axis2" />
<call>
<endpoint>
<address uri="vfs:file:///home/wso2carbon/attachments/"></address>
</endpoint>
</call>
<payloadFactory media-type="xml">
<format>
<Response>
<Message>Attachment has been uploaded.</Message>
</Response>
</format>
<args></args>
</payloadFactory>
<respond />
</inSequence>
<outSequence>
<send />
</outSequence>
<faultSequence />
</resource>
</api>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment