gpt4 book ai didi

http - 如何使用 Apache-nifi 的 InvokeHttp 处理器发送带有附加文件的 http POST multipart/form-data 请求?

转载 作者:行者123 更新时间:2023-12-05 07:23:18 27 4
gpt4 key购买 nike

我正在尝试使用 Nifi 的 InvokeHTTP 处理器向 POST API 发送多部分/表单数据请求。此请求需要一个 json 和一个文件。 POSTMAN 中的请求 header 和请求正文看起来像这样 -

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 中发送这个 multipart/form-data 请求。根据我在其中一个论坛上看到的答案(抱歉没有指向它的链接),我试图在将流文件发送到 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} - 默认值和

然后看看你的POST之后的输出是什么 enter image description here

关于http - 如何使用 Apache-nifi 的 InvokeHttp 处理器发送带有附加文件的 http POST multipart/form-data 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56062323/

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