【问题标题】:Mule flow adding weird characters to beginning of file骡流向文件开头添加奇怪的字符
【发布时间】:2026-02-03 09:30:01
【问题描述】:

我只是在移动文件,但出于某种原因,它们在文件的前面附加了奇怪的字符。 之前:

(使用 UTF-8 编码)

testCol1,testCol2,testCol3

之后:(用 ANSI 编码)

¬í ur [B¬óøTà  xp  žÌtestCol1,testCol2,testCol3

我尝试过的事情:

将编码显式设置为 utf-8。

将编码显式设置为 ANSI。

使用编码设置为 utf-8 的对象到字节数组。

使用编码设置为 utf-8 的对象转字符串。

这是我的流程和相关连接器:

<sftp:connector name="Sftp" maxConnectionPoolSize="3" doc:name="SFTP"/>
<file:connector name="FileConnector" autoDelete="true" streaming="false" validateConnections="true" doc:name="FileConnector"/>

<flow name="SftpOutBound" initialState="stopped">
    <file:inbound-endpoint
        path="${ftp.base}/${id}/export"
        pollingFrequency="${polling.frequency.millis}"
        responseTimeout="${standard.response.timeout.millis}"
        fileAge="${standard.fileage.delay.millis}"
        connector-ref="deletingFileConnector"
        doc:name="OutBound">
        <file:filename-wildcard-filter pattern="${out.filter}" />
    </file:inbound-endpoint>
    <object-to-byte-array-transformer doc:name="Object to Byte Array" />

    <all doc:name="all">
        <file:outbound-endpoint
            path="${archive.out}/${id}"
            outputPattern="#[header:INBOUND:originalFileName]_#[function:datestamp:${standard.date.format}]_#[function:systime]"
            responseTimeout="${standard.response.timeout.millis}"
            connector-ref="deletingFileConnector"
            doc:name="Archive" />
        <logger
            level="WARN"
            message="Uploaded file from ${ftp.base}/${id}/export/#[header:INBOUND:originalFileName]"
            doc:name="Logger"/>
        <sftp:outbound-endpoint
            connector-ref="Sftp"
            host="${host}"
            port="${port}"
            path="${in.path}"
            user="${user}"
            identityFile="${configFullPath}/${identity.file}"
            passphrase="${passphrase}"
            responseTimeout="${standard.response.timeout.millis}"
            keepFileOnError="true"
            duplicateHandling="overwrite"
            exchange-pattern="one-way"
            outputPattern="#[header:INBOUND:originalFileName]"
            doc:name="SFTP"/>
    </all>
</flow>

感谢您的帮助!

【问题讨论】:

    标签: encoding utf-8 mule


    【解决方案1】:

    所以这似乎是 Mule 3.5.0 的问题,当我升级到 3.6.1 时,问题就消失了。仍然不确定是什么原因造成的,但版本更改解决了它。

    【讨论】:

      【解决方案2】:

      来自 file:inbound-endpoint 的负载结果是 InputStream 类型。你为什么不保持原样 (byte[]) 由文件和 sftp 出站端点保存?

      如果你必须将它转换成字符串,那么我建议你阅读后使用&lt;byte-array-to-string-transformer /&gt;而不是&lt;object-to-byte-array-transformer /&gt;

      【讨论】:

      • 我试着不做任何事情,让端点处理它,它仍然有问题。这就是我最初的想法,然后我尝试了我在帖子中列出的所有内容。