Post 文件从 mule 到 API

Post file from mule to API

我正在向第三方提交文件api。我可以使用邮递员发出请求,第三方接受响应:

我的 mule 流以 http 请求开始,我可以在 message.inboundAttachments 字典中发送文件,但我不确定如何在 mule 流中向第三方构建请求。当我尝试将 message.InboundAttachment['Contract'] 项设置到负载中时,我只收到一条通用消息:

"Error sending HTTP request. Message payload is of type: DataHandler"

我不确定是什么问题。

更新 下面是我尝试使用附件组件的部分流程的屏幕截图:

附件组件如下所示:

<set-attachment attachmentName="#[message.inboundAttachments.Contract.dataSource.part.fileName]" value="#[message.inboundAttachments['Contract'].getInputStream()]" contentType="multipart/form-data" doc:name="Attaching Contract"/>

我在尝试发送时收到以下错误:

> ERROR 2016-05-03 11:26:45,597
> [[pan.internal.api].api-httpListenerConfig.worker.01]
> org.mule.exception.DefaultMessagingExceptionStrategy: 
> ******************************************************************************** Message               : Error sending HTTP request. Message payload is
> of type: NullPayload Type                  :
> org.mule.api.MessagingException Code                  : MULE_ERROR--2
> JavaDoc               :
> http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
> Payload               : {NullPayload}
> ******************************************************************************** Exception stack is:
> 1. Remotely closed (java.io.IOException)
> 2. java.io.IOException: Remotely closed (java.util.concurrent.ExecutionException)  
> org.glassfish.grizzly.impl.SafeFutureImpl$Sync:349 (null)
> 3. java.util.concurrent.ExecutionException: java.io.IOException: Remotely closed (java.io.IOException)  
> org.mule.module.http.internal.request.grizzly.GrizzlyHttpClient:245
> (null)
> 4. Error sending HTTP request. Message payload is of type: NullPayload (org.mule.api.MessagingException)  
> org.mule.module.http.internal.request.DefaultHttpRequester:287
> (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
> ******************************************************************************** Root Exception stack trace: java.io.IOException: Remotely closed
> 
> ********************************************************************************

我也曾尝试清除附件内容类型字段,但它似乎是必需的,并且也会引发错误。有什么想法吗?

您不需要将附件添加为请求的负载,您需要做的是将它从 InboundAttachments 移动到 OutboundAttachments。请求者组件将检测到存在 OutboundAttachments 并使用它们执行 multipart/form-data 请求。

HTH

更新 复制附件将正确设置内容长度并传递内容,而不是设置附件:

<copy-attachments attachmentName="Contract"   doc:name="Attaching Contract"  />