如何通过HTTP请求发送文件并通过Mule中的FTP将其上传到文件服务器 [英] How send a file in an HTTP request and upload it to file server via FTP in Mule
问题描述
我想通过HTTP POST请求发送文件,然后让Mule使用FTP将文件上传到服务器上的文件目录。它看起来像FTP连接器将有效负载保存到文件目录,但是这是通过为空,并通过FTP将空文件写入目录。
我使用邮递员在二进制/八位字节流作为raml和http请求中的媒体类型方面取得了一些成功,但文件未打开并且看起来像是可能被损坏,当我在raml和http请求中使用表单数据作为媒体类型时,它将显示为message.inboundAttachments中的键值对,但是如何从inboundAttachments中获取FTP连接器来写入。我已经尝试将它设置为显示为javax对象的有效负载,但在将其写入文件目录时存在问题。我该如何做到这一点,最好的方法是什么?文件将是文件> = 1,并且可能是不同的文件类型。我现在只是用一个文件来测试它。
另外,写入文件的名称为28f42420-b325-11e7-8ffb-dcb320524153.dat。如何指定名称,因为它看起来像message.inboundProperties.originalFilename为空?
我使用Anypoint Studio 6.2和Mule 3.8.3和Postman进行http调用,因为Mule控制台似乎没有提供发送文件的选项请求。
RAML
/ ftp:
displayName:FTP测试
描述:使用FTP将文件发送到目录
发布:
描述:发送文件
正文:
二进制/ stream:
multipart / form-data:
application / x-www-form-urlencoded:
属性:
文件:
描述:要上传的文件
要求:真
类型:文件
响应:
200:
body:
application / json:
c>< flow name =sendFtpFile>
< set-payload value =#[message.inboundAttachments.file]doc:name =Set Payload/>
< / flow>
谢谢
要在Mule api中读取这些文件,可以使用for-each构造,如下所示可能很有用:
< foreach doc:name =For Eachcollection =#[message.inboundAttachments]>
< set-payload value =#[payload.dataSource.content]doc:name =Set Payload/>
< logger message =Content: - #[payload]level =INFOdoc:name =Logger/>
< / foreach>
阅读后,您可以根据需要编辑或转换文件,并使用设置将其添加为附件 - 附件
< set-attachment attachmentName =requiredFile.xmlvalue =#[payload] contentType =text / xmldoc:name =Attachment/>
然后您可以将它发送到所需的FTP连接器。
I want to send a file in a HTTP POST request and then have Mule upload the file to a file directory on a server using FTP. It looks like the FTP connector saves the payload to the file directory but this is coming through as null and an empty file is written to the directory by FTP.
I've had some success with binary/octet stream as the media type in the raml and http request using Postman but the file doesn't open and looks like it may be corrupted and when I use form-data as the media type in the raml and http request it shows as a key value pair in message.inboundAttachments but how do I get the FTP connector to write from inboundAttachments. I have tried setting it as the payload which shows as an javax object but has problems when writing it to the file directory. How can I do this and what is the best approach to take? Files would be files >= 1 and could be different file types. I'm currently just testing it with one file.
Also, when the file is written is is named 28f42420-b325-11e7-8ffb-dcb320524153.dat. How can I specify the name as it looks like message.inboundProperties.originalFilename is null?
I'm using Anypoint Studio 6.2 and Mule 3.8.3 and Postman to make the http calls as Mule console does not appear to give the option to send a file in the request.
RAML
/ftp:
displayName: FTP Test
description: Send file to directory using FTP
post:
description: Send file
body:
binary/octet-stream:
multipart/form-data:
application/x-www-form-urlencoded:
properties:
file:
description: The file to be uploaded
required: true
type: file
responses:
200:
body:
application/json:
Current XML flow
<flow name="sendFtpFile">
<set-payload value="#[message.inboundAttachments.file]" doc:name="Set Payload"/>
<ftp:outbound-endpoint host=${host} port="21" path=${filePath} user=${user} password=${pwd} connector-ref="FTP" responseTimeout="10000" doc:name="FTP"/>
</flow>
Thanks
RAML to send multiple files to Mule api/endpoint could be defined as mentioned in answer to the post below-
Send multiple Files in HTTP request using RAML
To read these files in Mule api,you can use a for-each construct,something like below could be useful:
<foreach doc:name="For Each" collection="#[message.inboundAttachments]">
<set-payload value="#[payload.dataSource.content]" doc:name="Set Payload"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="Content :- #[payload]" level="INFO" doc:name="Logger"/>
</foreach>
Once read you can edit or transform the file as required and add it as attachment using set-attachment
<set-attachment attachmentName="requiredFile.xml" value="#[payload]" contentType="text/xml" doc:name="Attachment"/>
And then you can send it to required FTP connector.
这篇关于如何通过HTTP请求发送文件并通过Mule中的FTP将其上传到文件服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!