Mule3 上传附件到 SFTP 服务器

Mule3 Upload attachment to a SFTP server

我想按原样将附件上传到从 HTTP 入站获取的 SFTP 服务器。这些文件可以是任何类型,例如 XML、JSON、txt 等。

我尝试了这些示例代码,但问题是上传文件的格式与我发送的类型不符。它总是像 1f144250-7b46-11ea-a605-38f9d3744a4d.dat 一样存储在 FTP 服务器中。

    <flow name="FtpUp">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/attach1" doc:name="Copy_of_HTTP"/>
        <logger message="#[message.inboundAttachments.size()]" level="INFO" doc:name="Copy_of_Logger"/>
        <foreach collection="#[message.inboundAttachments]" doc:name="Copy_of_For Each">
            <set-payload value="#[payload.dataSource.content]" doc:name="Set Payload"/>
            <byte-array-to-string-transformer doc:name="Byte Array to String"/>
            <set-attachment attachmentName="test.txt" value="#[payload]" contentType="text/plain" doc:name="Attachment"/>
            <sftp:outbound-endpoint exchange-pattern="request-response" host="" port="22" path="" user="" password="" responseTimeout="10000" doc:name="SFTP"/>
        </foreach>
    </flow>
    <flow name="Copy_of_FtpUp">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/attach2" doc:name="Copy_of_Copy_of_HTTP"/>
        <foreach collection="#[message.inboundAttachments]" doc:name="Copy_of_Copy_of_For Each">
            <set-payload value="#[payload.dataSource.content]" doc:name="Set Payload"/>
            <sftp:outbound-endpoint exchange-pattern="request-response" host="" port="22" path="" user="" password="" responseTimeout="10000" doc:name="Copy_of_SFTP" disableTransportTransformer="true"/>
        </foreach>
    </flow>

有人可以帮我找出遗漏的部分吗?我只想上传文件,因为我正在进入 HTTP 入站。我正在使用 Mulesoft 3 (3.9.4 EE)。

问题可能是 SFTP 出站端点未设置 outputPattern 属性来定义输出文件的名称。默认值是消息 ID,它解释了您收到的名称。

outputPattern

The pattern to use when writing a file to disk. This can use the patterns supported by the filename-parser configured for this connector. By default the File Transport Reference is used. See this same document section for information on how to override the default parser.

Type: String

Default: The message ID, for example, ee241e68-c619-11de-986b-adeb3d6db038

此外,流程正在将文件作为附件发送。 SFTP 连接器期望要传输的文件内容在有效负载中。

这是遵循@aled 建议后的有效代码片段。

<flow name="FtpUp">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/attach2" doc:name="HTTP"/>
    <foreach collection="#[message.inboundAttachments]" doc:name="Iterate attachments ">
        <set-variable variableName="fileName" value="#[payload.dataSource.part.fileName]" doc:name="Set File Name"/>
        <set-payload value="#[payload.dataSource.content]" doc:name="Set Payload"/>
        <sftp:outbound-endpoint exchange-pattern="request-response" host="" port="22" path="" user="" password="" responseTimeout="10000" doc:name="SFTP Server" disableTransportTransformer="true" outputPattern="#[flowVars.fileName]"/>
    </foreach>
</flow>