如何获取CloudHub上MuleSoft项目生成的Excel文件?
如何查看CloudHub中MuleSoft应用生成的Excel文件
你在CloudHub部署的MuleSoft应用将Excel文件写入路径${mule.home}/apps/${app.name}/FIN.xlsx,以下几种方法可以查看该文件:
方法1:通过Runtime Manager文件浏览器访问
- 登录Anypoint Platform,进入Runtime Manager
- 找到目标应用,进入应用详情页
- 切换到Files标签页
- 在文件浏览器中导航到
/opt/mule/apps/[你的应用名称]/(CloudHub中${mule.home}对应/opt/mule) - 找到
FIN.xlsx文件,点击即可下载到本地查看
方法2:修改应用流程,添加HTTP下载端点
在现有流程末尾新增一个HTTP监听流,通过HTTP请求直接获取文件。示例修改如下:
<!-- 在现有flow外添加新的下载流 --> <flow name="downloadExcelFlow" doc:id="download-flow-id"> <http:listener doc:name="Download Listener" config-ref="HTTP_Listener_config" path="/download-fin"/> <file:read doc:name="Read Excel File" config-ref="File_Config" path="${mule.home}/apps/${app.name}/FIN.xlsx"/> <http:response-header doc:name="Set Download Headers"> <http:header key="Content-Disposition" value="attachment; filename=FIN.xlsx"/> <http:header key="Content-Type" value="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/> </http:response-header> </flow>
部署修改后的应用后,访问[你的CloudHub应用域名]:8081/download-fin即可下载文件。
方法3:SSH连接到CloudHub Worker(需企业版权限)
如果使用CloudHub企业版,可通过SSH连接到应用所在Worker:
- 在Runtime Manager应用详情页的SSH标签页获取连接信息
- 使用SSH客户端登录Worker,执行命令操作文件:
# 进入文件所在目录 cd /opt/mule/apps/[你的应用名称]/ # 查看文件状态 ls -l FIN.xlsx # 通过scp下载到本地(本地终端执行) scp [worker用户名]@[worker地址]:/opt/mule/apps/[你的应用名称]/FIN.xlsx ./本地保存路径
方法4:改用云存储(推荐)
CloudHub本地文件系统为临时存储,Worker重启后文件会丢失。建议将文件写入AWS S3、Azure Blob Storage等云存储服务,通过对应存储控制台直接访问,同时保证数据持久化。
你的示例代码
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd"> <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="8629addc-423c-4e55-b620-1291af64f3a2" > <http:listener-connection host="0.0.0.0" port="8081" /> </http:listener-config> <file:config name="File_Config" doc:name="File Config" doc:id="fe9d640c-d102-49d3-8d20-f459eee91837" /> <flow name="myinsightsFlow" doc:id="85b09215-b002-4db7-bb76-ef70d131bcb6" > <http:listener doc:name="Listener" doc:id="e59ec33b-1df0-44b3-983e-f61e8ec09dbc" config-ref="HTTP_Listener_config" path="/myInsight"/> <set-variable value="#[payload]" doc:name="Set Variable" doc:id="0258fa4a-3f6e-4f20-8fca-9fca5a093dcc" variableName="firstPayload"/> <logger level="INFO" doc:name="Payload From Listener" doc:id="d335d098-35f5-46b0-94e1-c9fa6427451f" message="#[vars.firstPayload]"/> <ee:transform doc:name="Transform Message" doc:id="378829cf-8268-462d-9946-a24efa7b6955" > <ee:message > <ee:set-payload ><![CDATA[%dw 2.0 output application/json // Calculate the count of queries var queryCount = sizeOf(vars.firstPayload) --- { "queryCount": queryCount } ]]></ee:set-payload> </ee:message> </ee:transform> <logger level="INFO" doc:name="QueryCount" doc:id="19e5d841-e814-40bf-aa28-155564e7a64a" message="#[payload]"/> <ee:transform doc:name="Transform Message" doc:id="e88474af-ff3a-4cc9-a05c-953ab3401380" > <ee:message > <ee:set-payload ><![CDATA[%dw 2.0 output application/xlsx header=true // Calculate the count of queries --- { "Sheet1":vars.firstPayload } ]]></ee:set-payload> </ee:message> </ee:transform> <file:write doc:name="Write" doc:id="ed392aa2-ecb8-41e0-9cf8-6fb6c89ea228" config-ref="File_Config" path="${mule.home}/apps/${app.name}/FIN.xlsx"/> </flow> </mule>
内容的提问来源于stack exchange,提问作者TwinZaia
相关产品推荐
相关产品推荐

