gpt4 book ai didi

java - 从上传的文件中获取文件名 mule esb 3.6

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:27 26 4
gpt4 key购买 nike

我正在尝试使用 mule 3.6 开发一个休息层,我在其中通过 POST 方法接收文件上传。

我创建了以下流程:

<flow name="post:/campaigns/{campaignId}/files:multipart/form-data:api-config">
<logger message="#[flowVars.nameFile]" level="INFO" doc:name="Logger"/>
<foreach collection="#[message.inboundAttachments]" doc:name="Foreach">
<file:outbound-endpoint path="C:\Users\valter.gomes\Desktop\Nova pasta" outputPattern="#[message.outboundProperties]" connector-ref="File" responseTimeout="10000" doc:name="File"/>
</foreach>

</flow>

但是我无法获取上传文件的名称。我试过:#[message.outboundProperties.filename] , #[message.inboudProperties.filename] , #[header:filename]

但是堆栈跟踪是:

    Message               : Failed to route event via endpoint:   `enter code here`DefaultOutboundEndpoint{endpointUri=file:///C:/Users/valter.gomes/Desktop/Nova%20pasta/, connector=FileConnector
{
name=File
lifecycle=start
this=7f3f15d8
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[file]
serviceOverrides=<none>
}
, name='endpoint..C.Users.valter.gomes.Desktop.Nova pasta', mep=ONE_WAY, properties={outputPattern=#[header:filename]}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: DataHandler
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Expression Evaluator "header" with expression "outbound:filename" returned null but a value was required. (org.mule.api.expression.RequiredValueException)
org.mule.expression.ExpressionUtils:235 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/RequiredValueException.html)
2. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=file:///C:/Users/valter.gomes/Desktop/Nova%20pasta/, connector=FileConnector
{
name=File
lifecycle=start
this=7f3f15d8
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[file]
serviceOverrides=<none>
}
, name='endpoint..C.Users.valter.gomes.Desktop.Nova pasta', mep=ONE_WAY, properties={outputPattern=#[header:filename]}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: DataHandler (org.mule.api.transport.DispatchException)
org.mule.transport.AbstractMessageDispatcher:117 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.expression.RequiredValueException: Expression Evaluator "header" with expression "outbound:filename" returned null but a value was required.
at org.mule.expression.ExpressionUtils.getPropertyInternal(ExpressionUtils.java:235)
at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:63)
at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:46)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

请问有人知道如何使用 file:outbound-endpoint 获取此文件名吗?或者还有其他方法可以做到这一点吗?

感谢您的关注,

瓦尔特·戈麦斯

最佳答案

file:outbound-endpoint 不会在任何属性中存储其创建的文件名。

但是,它可以通过名为 filename 的出站属性名称接收文件名。因此,您可以预先分配此名称(例如使用随机 UUID)并将其设置为端点的出站属性以获取它。

引用:https://github.com/mulesoft/mule/blob/mule-3.6.2/transports/file/src/main/java/org/mule/transport/file/FileMessageDispatcher.java#L58-L63

关于java - 从上传的文件中获取文件名 mule esb 3.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30159311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com