无法使用WSO2 EI文件连接器查看下载的图像

问题描述 投票:1回答:1

我正在使用WSO2 EI文件连接器将图像下载到本地文件夹,图像已成功下载,但无法查看。有人请帮助我吗?

注意: Bae64来自API,此处未包含。 base64内容仅是正确的,因为我可以使用base64 to Image converter从此base64中获取准确的图像在以下的axis2.xml文件中添加。

<messageFormatter contentType="application/octet-stream" class="org.apache.axis2.format.BinaryFormatter"/>
    <messageBuilder contentType="application/octet-stream" class="org.apache.axis2.format.BinaryBuilder"/>

代码段:

<sequence name="DownloadImageFileSequnce" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log level="custom">
        <property name="===DownloadImageFileSequnce" value="called=="/>
    </log>
            <property value="D:\Test\CarSalesStockImages" name="PATH"/>
            <property expression="get-property('StockNo')" name="FOLDERNAME"/>
            <property expression="get-property('eachImageName')" name="FILENAME"/>
            <property expression="get-property('image_val')" name="CONTENT"/>

    <!-- <property name="messageType" value="application/octet-stream" scope="axis2"/> -->
    <property expression="fn:concat('file://',$ctx:PATH,'/',$ctx:FOLDERNAME,'/',$ctx:FILENAME)" name="source"/>
        <log level="custom">
        <!-- <property name="===CONTENT===" expression="get-property('CONTENT')"/> -->
        <property name="===PATH===" expression="get-property('PATH')"/>
        <property name="===FOLDERNAME===" expression="get-property('FOLDERNAME')"/>
        <property name="===FILENAME===" expression="get-property('FILENAME')"/>
        <property name="===source===" expression="get-property('source')"/>
    </log>
        <fileconnector.isFileExist>
                <source>{$ctx:source}</source>
            </fileconnector.isFileExist>
            <property expression="json-eval($.fileExist)" name="exists" type="BOOLEAN"/>
            <filter xpath="$ctx:exists">
                <then>
                    <fileconnector.append>
                        <destination>{$ctx:source}</destination>
                        <inputContent>{$ctx:CONTENT}</inputContent>
                    </fileconnector.append>
                    <payloadFactory media-type="json">
                        <format>{"status":"File updated"}</format>
                        <args/>
                    </payloadFactory>
                    <log level="custom">
                    <property name="==Response==" expression="json-eval($.)"/>
                    </log>
                </then>
                <else>
                    <fileconnector.create>
                        <source>{$ctx:source}</source>
                        <inputContent>{$ctx:CONTENT}</inputContent>
                    </fileconnector.create>
                    <payloadFactory media-type="json">
                        <format>{"status":"File created"}</format>
                        <args/>
                    </payloadFactory>
                    <log level="custom">
                    <property name="==Response==" expression="json-eval($.)"/>
                    </log>
                </else>
            </filter>
</sequence>
image file wso2ei
1个回答
0
投票

我已经找到了通过使用vfs而不是wso2文件连接器的解决方案。

    <?xml version="1.0" encoding="UTF-8"?>
<sequence name="DownloadImageFileSequnce" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log level="custom">
        <property name="===DownloadImageFileSequnce" value="called=="/>
    </log>
    <property name="PATH" scope="default" type="STRING" value="D:\Test\CarSalesStockImages"/>
    <property expression="get-property('StockNo')" name="FOLDERNAME" scope="default" type="STRING"/>
    <property expression="get-property('eachImageName')" name="FILENAME" scope="default" type="STRING"/>
    <property expression="get-property('image_val')" name="CONTENT" scope="default" type="STRING"/>
    <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:CONTENT"/>
        </args>
    </payloadFactory>
    <script language="js"><![CDATA[var binaryNode =       
      mc.getEnvelope().getBody().getFirstElement().getFirstOMChild();  
   binaryNode.setBinary(true);]]></script>
    <!-- <property expression="concat($ctx:PATH,'/',$ctx:FOLDERNAME,'/',$ctx:FILENAME)" name="transport.vfs.ReplyFileName" scope="transport" type="STRING"/> -->
    <property expression="concat('vfs:file:///',$ctx:PATH,'/',$ctx:FOLDERNAME,'/',$ctx:FILENAME)" name="localpath"/>
     <header name="To" expression="get-property('localpath')"/>
    <log level="custom">
        <property expression="$ctx:localpath" name="==ReplyFileName==="/>
    </log>
    <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
    <property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
    <property name="messageType" scope="axis2" type="STRING" value="application/octet-stream"/>
    <call/>
    <payloadFactory media-type="json">
        <format>
                {                
                    "status": "success",                
                    "statusMessage" : "Image downloaded"               
                }            
             </format>
        <args/>
    </payloadFactory>
    <log level="custom">
        <property expression="json-eval($.)" name="Response"/>
    </log>

</sequence>
© www.soinside.com 2019 - 2024. All rights reserved.