gpt4 book ai didi

mule - 接收 PDF 文件并转发它而不改变它

转载 作者:行者123 更新时间:2023-12-02 04:54:10 26 4
gpt4 key购买 nike

我需要公开一个网络服务,用户可以在其中通过 POST 请求向我发送 PDF 文件。我不想更改此文件。只需将其存储在云端的容器中即可。

这是我用来测试服务的 curl :

curl -X POST -H "Content-type: application/pdf"  'http://localhost:9302/billing/1/storeInvoice/user/0750102626/invoice/666' --data-binary /Users/manu/Desktop/toto.pdf

这是我的流程的 XML 代码:

<flow name="storebill">
<http:inbound-endpoint exchange-pattern="request-response" host="${inbound.host}" port="9302" path="storeInvoice/" method="POST" contentType="application/pdf"/>
<custom-transformer class="BuildFileNameFromRequestPath" />
<http:outbound-endpoint exchange-pattern="request-response" host="myHost" port="80" path="#[flowVars['fileName']" contentType="application/pdf" method="PUT"/>
<exception-strategy ref="genericExceptionStrategy" />
</flow>

该文件很好地存储在我的 openstack 容器中,但它的编码完全错误。当我下载以前存储的文件时,我无法在我的笔记本电脑上阅读它。

PS:当我在 openstack 容器中通过 curl 上传我的本地 PDF 时,它的编码很好。

BuildFileNameFromRequestPath 转换器的代码:

public class BuildFileNameFromRequestPath extends AbstractMessageTransformer {

public Object transformMessage(MuleMessage message, String outputEncoding) throws BusinessException {

String request = message.getInboundProperty("http.request");
StoreBillInfo result = getRestInfo(request);

if (result != null) {
message.setProperty(VariableNamesConstant.VAR_STOREBILLINFO, result, PropertyScope.INVOCATION);
} else {
throw new BusinessException(ErrorCode.ERR400);
}

try {
System.out.println("length payload : " + message.getPayloadAsBytes().length);
return message.getPayloadAsBytes();
} catch (Exception e) {
throw new BusinessException(ErrorCode.ERR400);
}
}
}

getRestInfo 只是一种从路径中提取一些信息以构造 pdf 文件名的方法。

最佳答案

不要使用 message.getPayloadAsBytes() 来扰乱消息负载。您无缘无故地反序列化流,并且可能会弄乱编码。

不使用自定义转换器,而是使用带有静态调用 getRestInfo 的 MEL 表达式的 set-variable 元素。

关于mule - 接收 PDF 文件并转发它而不改变它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24635932/

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