尽管启用了MTOM,为什么仍对二进制内容进行base64编码?

问题描述

我想将multipart / form-data上载到WSO2 Micro Integrator REST API,保存一些部分,然后将消息中继到另一个 后端服务,同样也是multipart / form-data。但是,二进制数据 我上传的图像在传输到 后端服务,尽管我启用了MTOM。而且,做东西 更有趣的是,当我上传文件名为“ tree.jpg”的图像时, 零件名称“图像”,传出的multipart / form-data主体表示 零件名称是“文件”。

我使用了<property name="enableMTOM" scope="axis2" type="STRING" value="true" /> 激活MTOM。

我也尝试过

[server]
enable_mtom = true

https://ei.docs.wso2.com/en/latest/micro-integrator/use-cases/examples/endpoint_examples/mtom-swa-with-endpoints/所述。

然后我在地址端点中使用了@optimize="mtom"。我也试过 范围为axis2-client的财产调解人,其中一些人非常绝望 自定义类介体中的方法

有什么想法我想念的吗?

这是API定义:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/imageupload" name="ImageUpload"
    xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST">
        <inSequence>
            <log level="full" />
            <property name="enableMTOM" scope="axis2" type="STRING"
                value="true" />
            <property name="HTTP_METHOD" scope="axis2" type="STRING"
                value="POST" />
            <property name="messageType" scope="axis2" type="STRING"
                value="multipart/form-data" />
            <call>
                <endpoint>
                    <address optimize="mtom"
                        uri="http://localhost:11112/image">
                    </address>
                </endpoint>
            </call>
            <respond />
        </inSequence>
        <outSequence />
        <faultSequence />
    </resource>
</api>

以下是curl命令以调用API:

curl --location --request POST 'host:11112/image' \
--form 'image=@/C:/path/to/tree.jpeg'

后端收到的是:

Content-Type: [multipart/form-data; charset=UTF-8 ...
--MIMEBoundary_cd4e6032101efe8a3e0dbf4041d34990229f3a11b5986f04
Content-disposition: form-data; name="file"; filename="tree.jpeg"
Content-Type: image/jpeg; charset=ISO-8859-1
Content-transfer-encoding: binary

/9j/4AAQSkZJRgAB ... more base64 encoded content

有趣的是,当我注释掉呼叫调解人并且只拥有WSO2时 发回给我我收到的消息,这就是我得到的:

Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
Content-transfer-encoding: binary
Content-ID: <0.21badfa73e85a25afec993c9541c3fd5557dca3319e70177@apache.org>

<mediate><image filename="tree.jpeg" content-type="image/jpeg"><xop:Include
... href="cid:1.11badfa73e85a25afec993c9541c3fd5557dca3319e70177@apache.org"/>...
--MIMEBoundary_31badfa73e85a25afec993c9541c3fd5557dca3319e70177
Content-Type: image/jpeg
Content-transfer-encoding: binary
Content-ID: <1.11badfa73e85a25afec993c9541c3fd5557dca3319e70177@apache.org>

如果我用“ enableMTOM”注释掉属性介体,则会得到二进制文件 内容返回base64编码。因此,“ enableMTOM” 确实具有作用,并且上述 更接近我的期望,但是我的后端期望是二进制 内容,零件名称是“图像”,而不是“文件”,因此 以下:

Content-Type: [multipart/form-data; boundary=--------------------------574764981381931704793014]
----------------------------574764981381931704793014
Content-disposition: form-data; name="image"; filename="tree.jpeg"
Content-Type: image/jpeg

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)