Demo Code in WordPress

XML Code

<?xml version="1.0" encoding="UTF-8"?>
<api context="/getFile" name="getFile" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
            <call>
                <endpoint>
                    <http method="get" uri-template="https://yossishalom.com/wp-content/uploads/2022/04/test.pdf">
                    </http>
                </endpoint>
            </call>
            <property name="transport.vfs.ReplyFileName" scope="transport" type="STRING" value="test.pdf"/>
            <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
            <call>
                <endpoint>
                    <address uri="vfs:file:///c:/WSO2Folder/OUTPUT/">
                    </address>
                </endpoint>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>


JavaScript Code

<script language="nashornJs"><![CDATA[var log = mc.getServiceLog();
	var clientFiles = [];
	var attachments = new Array;

	var attachmentNum = -1;
	
	if (mc.getProperty("base64FileFiles"))
	{
		clientFiles = JSON.parse(mc.getProperty("base64FileFiles"));
		for (i = 0; i < clientFiles.length; ++i) {
			attachmentNum = attachmentNum + 1;
			attachment = new Object();
			attachment.name = clientFiles[i].fileName;
			var base64File = clientFiles[i].base64;
			var base64DataObj = base64File.split(',');
			attachment.content = base64DataObj[1];
			attachments[attachmentNum] = attachment;
		}
	}
	else{
		log.info("********** didnt get base64FileFiles **************");
	}
	
	if (mc.getProperty("base64FileFiles_2")){
		clientFiles_2 = JSON.parse(mc.getProperty("base64FileFiles_2"));
		for (i = 0; i < clientFiles_2.length; ++i) {
			attachmentNum = attachmentNum + 1;
			attachment = new Object();
			attachment.name = clientFiles_2[i].fileName;
			var base64File = clientFiles_2[i].base64;
			var base64DataObj = base64File.split(',');
			attachment.content = base64DataObj[1];
			attachments[attachmentNum] = attachment;
		}
	}
	else{
		log.info("********** didnt get base64FileFiles_2 **************");
	}
	
	mc.setProperty("attachmentFiles",JSON.stringify(attachments));]]>
</script>