[英]Mule3 Upload attachment to a SFTP server
我想将附件原样上传到从 HTTP 入站获取的 SFTP 服务器。 这些文件可以是任何类型,例如 XML、JSON、txt 等。
我尝试了这些示例代码,但问题是上传文件的格式不是我发送的类型。 它始终存储在 FTP 服务器中,例如1f144250-7b46-11ea-a605-38f9d3744a4d.dat
。
<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属性来定义 output 文件的名称。 默认值为消息 id,它解释了您获得的名称。
输出模式
将文件写入磁盘时使用的模式。 这可以使用为此连接器配置的文件名解析器支持的模式。 默认情况下使用文件传输参考。 有关如何覆盖默认解析器的信息,请参阅此文档部分。
类型:字符串
默认值:消息 ID,例如 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.