WSO2 ESB: How to write a file from Base64 with VFS?

≡放荡痞女 提交于 2019-12-12 05:33:21

问题


I have pretty much the same issue as this person: WSO2 ESB - writing files out of base64

However, in the answer to that question there was no mention of how to decode the Base64 string in JavaScript and attach it to the payload. That's what I'm interested in.

Thanks in advance,

Strainy


回答1:


Went with a slightly different approach. I created a utility proxy service to re-download the file and then push it into the file system.

utilty_createFile Proxy Service

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="utility_createFile"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target inSequence="utility_createFile_IN" outSequence="utility_createFile_OUT"/>
   <description/>
</proxy>

utility_createFile_IN Sequence

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="utility_createFile_IN" onError="fault" xmlns="http://ws.apache.org/ns/synapse">
    <property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
    <property expression="//createFile/download_folder"
        name="uri.var.download_folder" xmlns:ns="http://org.apache.synapse/xsd"/>
    <property expression="//createFile/url" name="uri.var.download_url" xmlns:ns="http://org.apache.synapse/xsd"/>
    <script language="js"><![CDATA[var download_url = mc.getProperty('uri.var.download_url');
download_url = decodeURIComponent(download_url);
mc.setProperty('uri.var.download_url', download_url);]]></script>
    <send>
        <endpoint>
            <http method="GET" uri-template="{uri.var.download_url}"/>
        </endpoint>
    </send>
</sequence>

utility_createFile_OUT Sequence

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="utility_createFile_IN" onError="fault" xmlns="http://ws.apache.org/ns/synapse">
    <property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
    <property expression="//createFile/download_folder"
        name="uri.var.download_folder" xmlns:ns="http://org.apache.synapse/xsd"/>
    <property expression="//createFile/url" name="uri.var.download_url" xmlns:ns="http://org.apache.synapse/xsd"/>
    <script language="js"><![CDATA[var download_url = mc.getProperty('uri.var.download_url');
download_url = decodeURIComponent(download_url);
mc.setProperty('uri.var.download_url', download_url);]]></script>
    <send>
        <endpoint>
            <http method="GET" uri-template="{uri.var.download_url}"/>
        </endpoint>
    </send>
</sequence>


来源:https://stackoverflow.com/questions/35108253/wso2-esb-how-to-write-a-file-from-base64-with-vfs

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