如何使用Apache-nifi&nifi'的InvokeHttp处理器发送带有附加文件的http post multipart/form-data请求? [英] How to send an http POST multipart/form-data request with a file attached using Apache-nifi's InvokeHttp processor?

查看:40
本文介绍了如何使用Apache-nifi&nifi'的InvokeHttp处理器发送带有附加文件的http post multipart/form-data请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Nifi的InvokeHTTP处理器向POST API发送多部分/表单数据请求。该请求接受一个json和一个文件。Postman中的请求头和请求体如下所示-

POST /delivery/deliverPackage
User-Agent: PostmanRuntime/7.6.1
Accept: */*
Host: example.hostname:port
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------161413078116998145311888
content-length: 1115
json={ "destinationProtocol" : "HL7", "destinationFormat": "HL7_V2_ORU", "destinationType": "example", "destinationConnectionParams":{ "URI": "example", "HOST": "example", "PORT": "example" } }file=[object Object]

文件对象包含我尝试发送的文件详细信息的位置。

我想用NIFI发送此多部分/表单数据请求。根据我在其中一个论坛上看到的答案(对不起,没有指向它的链接),在将流文件发送到InvokeHttp处理器之前,我尝试使用ReplaceText处理器在流文件的内容中创建此请求体。流文件内容如下所示-

POST /delivery/deliverPackage
User-Agent: curl/7.46.0
Accept: */*
Host: example.hostname:port
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------161413078116998145311888
content-length: 1115

--------------------------161413078116998145311888
Content-Disposition: form-data; json="{ "destinationProtocol" : "HL7", "destinationFormat": "HL7_V2_ORU", "destinationType": "example", "destinationConnectionParams":{ "URI": "example", "HOST": "example", "PORT": "example" } }"

anonymous
--------------------------161413078116998145311888
Content-Disposition: form-data; name="file"; filename="/path/to/file/in/localsystem.HL7"
Content-Type: text/plain

contents of the file
--------------------------161413078116998145311888--

这似乎不管用,在我看来不太对劲。我对Nifi还是个新手。有没有人能帮我理解我做错了什么,或者给我一些关于如何正确处理这件事的见解?谢谢!

我尝试使用ExecuteStreamCommand处理器来简单地运行带有命令参数的curl命令-

-X POST;"https://example.hostname:port/delivery/deliverPackage?json=%7B%20%22destinationProtocol%22%20%3A%20%22HL7%22%2C%20%22destinationFormat%22%3A%20%22HL7_V2_ORU%22%2C%20%22destinationType%22%3A%20%22example%22%2C%20%22destinationConnectionParams%22%3A%7B%20%22URI%22%3A%20%22example%3A%2F%2Fexample%3A15050%22%2C%20%22HOST%22%3A%20%22example%22%2C%20%22PORT%22%3A%20%22example%22%20%7D%20%7D";-H "Content-Type: multipart/form-data";-F "file=@/path/to/file/in/localsystem.HL7";

这是可行的,但是我想知道如何使用InvokeHttp处理器来完成它。如有任何帮助,我们将不胜感激!谢谢您。

推荐答案

可以使用GenerateFlowFile-->InvokeHTTP执行此操作。

GenerateFlowFile将在"自定义文本"字段中创建帖子的有效负载(在您的情况下为localsystem.HL7的内容)。

InvokeHTTP需要将Content-Type设置为${mime.type}-默认值,

然后查看发布后的输出

这篇关于如何使用Apache-nifi&nifi'的InvokeHttp处理器发送带有附加文件的http post multipart/form-data请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆