如何使用 sftp:content 从内存中写入 sftp 消息

How do I use sftp:content to write an sftp message from memory

我正在尝试使用 sftp:write 和 sftp:content 从内存中创建一个 sftp 文件。我的数据编织代码是:

<sftp:write doc:name="sftp from memory" doc:id="01bee2a1-69ad-4194-8ec8-c12852521e87" config-ref="SFTP_Config" path="#[vars.sftpFileName]" createParentDirectories="false">
    <sftp:content><![CDATA[%dw 2.0
        output application/csv
        ---
        payload.toplevel.secondlevel.bottomlevel[0],
        payload.more.andmore.andstillmore[0]
        ]]>
    </sftp:content>
</sftp:write>

它确实在正确的目录中创建了一个文件,但内容不是负载值。相反,它是实际的数据编织代码。文件内容为:

%dw 2.0
output application/csv
---
payload.toplevel.secondlevel.bottomlevel[0]
payload.more.andmore.andstillmore[0]

我使用的是 Mule Server 4.2.2 版和 SFTP 组件的 1.3.2 版。

您实际上并不是在传递 dataweave,而是在传递一个字符串。当您要使用数据编织时,请按字段上的 fx 按钮。 XML 看起来像这样。注意到额外的 #[ 了吗?这表明这是数据编织。您的数据编织也无效;您必须输出一个 object 或一个 object 数组;为了让你的输出成为 object,你将它包装在 { .. } 中,就像 JSON 一样,并使用 key-value 对。将此输出为 CSV 时,键将用作 header 行,除非您在输出行中包含 header=falsehttps://docs.mulesoft.com/mule-runtime/4.3/dataweave-formats-csv#writer_properties

<sftp:write doc:name="sftp from memory" doc:id="01bee2a1-69ad-4194-8ec8-c12852521e87" config-ref="SFTP_Config" path="#[vars.sftpFileName]" createParentDirectories="false">
    <sftp:content><![CDATA[#[%dw 2.0
        output application/csv
        ---
        {
            someKeyName: payload.toplevel.secondlevel.bottomlevel[0],
            someOtherKeyName: payload.more.andmore.andstillmore[0]
        }]]]>
    </sftp:content>
</sftp:write>