从CloudHub Mulesoft获取excel文件

问题描述 投票:0回答:2

我的问题是我已经在cloudhub中部署了一个项目。该流程会将有效负载转换为 Excel 格式,并且 Excel 文件将位于我设置的路径中。

我知道本地和cloudhub的路径是不同的,所以我设置为这个 path:${mule.home}/apps/${app.name}/FIN.xlsx 。有什么办法可以让我在cloudhub中查看excel文件吗?感谢您的时间。编辑:这是我的示例代码:

    <?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>
dataweave mulesoft mule4 anypoint-studio mule-component
2个回答
0
投票

我有与您类似的要求,在我的流程中生成一个 csv 文件,该文件由应用程序中的专用流程读取和写入。在该过程结束时,我将 csv 附加到我发送的电子邮件中(使用带附件的 smtp 电子邮件发送)。因此,这证明我的文件是否正确生成,以及格式是否正确。


0
投票

在 CloudHub 应用程序中写入文件是一种不好的做法。执行 Mule 应用程序的 CloudHub Workers 是临时的,因此文件无法在重新启动后保存。工作人员的存储空间也有大小限制。在负载或大文件下,可能很容易使用所有可用空间并导致问题。在 REST API 或 HTTP 服务器实现中,客户端不需要读取输出文件。相反,期望是在请求的 HTTP 响应中接收文件。在这种情况下,删除流程末尾的

<file:write>
操作将导致已包含 Excel 文档的有效负载作为 HTTP 响应的正文发送。另一种选择是使用响应的多部分格式将其写入附件,而不是响应的完整正文。

© www.soinside.com 2019 - 2024. All rights reserved.