繁体   English   中英

如何使用Apache-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?

我正在尝试使用Nifi的InvokeHTTP处理器向POST API发送multipart / form-data请求。 此请求采用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中发送这个multipart / form-data请求。 根据我在其中一个论坛上看到的答案(抱歉没有链接),我试图在将流文件发送到InvokeHttp处理器之前使用ReplaceText处理器在flowfile的内容中创建这个请求体。 流文件内容看起来像这样 -

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后的输出结果 在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM