I have a visual program with which I am trying to create a http multipart post.
I have two context variables that contain, respectively, a string and a file.
The visual program consists of header and body,detached. In the header i insert
Content-Type multipart/form-data,but how can insert the variabile in the body and how can i indicate the different part the body and her name,how can insert in the header?
Your request could be formed as follows:
POST /your_page.html HTTP/1.1
Host: your.host.com
Content-Type: multipart/form-data; boundary=My_Boundary_1234567890
Content-Length: [length of request in bytes]
--My_Boundary_1234567890
Content-Disposition: form-data; name="MyVariableName"
my_valiable_value
--My_Boundary_1234567890
Content-Disposition: form-data; name="MyFile"; filename="picture.jpg"
Content-Type: image/jpeg
binary contents of the file
--My_Boundary_1234567890--
Just do not forget about new line after the last boundary.
Related
I am trying to send a multipart/form-data request to a POST API using Nifi's InvokeHTTP processor. This request takes a json and a file. The request headers and request body in POSTMAN look something like this -
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]
where the file object contains the file details I am trying to send.
I want to send this multipart/form-data request in nifi. Based on an answer I saw on one of the forums (sorry do not have the link to it), I am trying to create this request body in the content of the flowfile using ReplaceText processor before sending the flowfile to an InvokeHttp processor. The flowfile content looks something like this -
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--
This doesn't seem to be working though, it doesn't look right to me. I am pretty new to Nifi. Can anyone help me understand what I'm doing wrong or give some insights on how to handle this properly? Thanks!
I have instead tried to use an ExecuteStreamCommand processor to simply run the curl command with command arguments -
-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";
This works, but I wanted to know how to do it using the InvokeHttp processor. Any help is greatly appreciated! Thank you.
You can do this by using GenerateFlowFile --> InvokeHTTP.
The GenerateFlowFile would create the payload(in your case the content of localsystem.HL7) of your post in the Custom Text filed.
The InvokeHTTP will need to have Content-Type as ${mime.type} - default value and
Then see what the output is after your POST
I'm using Postman to learn how to use the Google Drive API.
I'm trying to upload an API to an image that is in a URL. I'm using the multipart upload described in this documentation link, but the example is not clear to me, I can upload a file with the metadata I'm passing, but the image of the URL I've placed is not being sent.
Please help me understand what I'm doing wrong. Below is the code for my request.
POST /upload/drive/v3/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Content-length: *
Authorization: [myToken]
Content-Type: multipart/related; boundary=test
Cache-Control: no-cache
Postman-Token: [postmanToken]
--test
Content-Type: application/json; charset=UTF-8
{
"name": "imageTest",
"parents": ["1Ij0ZR8yrubkHQaT6tSQNgK6AhW4gbP49"]
}
--test
Content-Type: image/*
https://download.shutterstock.com/gatekeeper/W3siZSI6MTUzNjcwMzQ0NSwiayI6InBob3RvLzEwMDcwNjYwMjMvaHVnZS5qcGciLCJtIjoxLCJkIjoic2h1dHRlcnN0b2NrLW1lZGlhIn0sInR3UkJ0bDZNYUJNUXJ2azZlaE9MbTZlT2VBbyJd/shutterstock_1007066023.jpg
--test--
I doubt that you will be able to use Postman to upload a file. Its going to have to read the file first and then send the file data in chunks.
All of the examples google has for this is using a programming language there is no samples of doing it directly with HTTP calls file upload
If it did work you would be looking at something like this. You are still going to need some language to read the file contents and add it to this.
POST / HTTP/1.1
[[ Less interesting headers ... ]]
Content-Type: multipart/form-data; boundary=---------------------------735323031399963166993862150
Content-Length: 834
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text1"
text default
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text2"
aωb
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain
Content of a.txt.
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html
<!DOCTYPE html><title>Content of a.html.</title>
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file3"; filename="binary"
Content-Type: application/octet-stream
aωb
-----------------------------735323031399963166993862150--
I am trying to send a file using HTTP from a C++ application (no HTML-boxes). The server keeps answering Code 400/ Bad Request.
To keep it simple, I have changed manually the content of the file to a simple string (later on, I will need to upload real binary files).
the POST request is the following:
POST /post.php HTTP/1.0
Host: posttestserver.com
Accept: */*
Content-Type: multipart/form-data; boundary=BOUNDARY
--BOUNDARY
Content-Disposition: form-data; name="userfile"; filename="example.txt"
Content-Type:text/plain
123ABC
--BOUNDARY--
Connection: close
Any idea what is going on?
I am attempting to upload a file to Google Drive using the "upload" URL with a type of "multipart". I'm trying to do this without a library and using basic HTTP with a multipart POST. With a body like the following, I am constantly getting the error "Invalid multipart request with 0 mime parts."
The HTTP message looks valid to me. Is there something obvious that I'm missing or doing wrong?
Is there a protocol tester that can verify if my POST body is valid or not?
POST /upload/drive/v2/files?uploadType=multipart HTTP/1.1
Authentiction: Bearer {valid auth_token}
Content-Type: multipart/mixed; boundary="--314159265358979323846"
host: localhost:3004
content-length: 254
Connection: keep-alive
--314159265358979323846
Content-Type: application/json
{"title":"Now","mimeType":"text/plain"}
--314159265358979323846
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Mon Jun 17 2013 20:59:02 GMT-0400 (EDT)
--314159265358979323846--
(The segments look like they have double newlines. I think this is an artifact of the pasting, they are CRLF pairs in the code and appear as a newline when testing, but I guess this could theoretically be the problem, but I'd like proof.)
boundary attribute on the Content-Type header should not include double dashes. Use the following as your Content-Type:
Content-Type: multipart/mixed; boundary="314159265358979323846"
How can I calculate content length for example of:
POST /Upload/ HTTP/1.1
Host: test.lan
User-Agent: Shockwave Flash
Connection: Keep-Alive
Cache-Control: no-cache
Accept: text/*
Content-Length: ?????
Content-Type: multipart/form-data; boundary=----------------------------4d2179e6b3c0
------------------------------4d2179e6b3c0
Content-Disposition: form-data; name="Filename"
phpinfo.php
------------------------------4d2179e6b3c0
Content-Disposition: form-data; name="ASPSESSID"
6e223eb1c7561e9c599f03cc04e9444b
------------------------------4d2179e6b3c0
Content-Disposition: form-data; name="Filedata"; filename="phpinfo.php"
Content-Type: application/octet-stream
<? phpinfo(); ?>
------------------------------4d2179e6b3c0
Content-Disposition: form-data; name="Upload"
Submit Query
------------------------------4d2179e6b3c0--
The Content-Length value should be calculated by totaling all data after the termination of the message headers. In the case of your example, this is everything after this point (with CRLF characters included for readability):
...
Content-Length: ?????\r\n
Content-Type: multipart/form-data; boundary=--------------------4d2179e6b3c0\r\n
\r\n
Everything coming after the first empty line (\r\n) -- including your boundary delimiters -- should be counted in the total length. In practice, this usually means that you'll need to tabulate the Content-Length header value after generating the full message entity body. Once you have the full body of the message you can prepend it with your headers to create the full HTTP message.
According to the HTTP spec you aren't technically required to specify the Content-Length header. From RFC 2616 14.13:
Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by the rules in section 4.4.
However, this is a pretty standard requirement for most servers which will generally send back an error response if the Content-Length is missing or incorrectly specified.