Webhook Relay
Search…
Multipart Form Data
Some services send data in multipart/formdata encoding. Webhook Relay automatically parses this data and presents it to your function code.
Webhook Relay detects multipart/formdata requests and automatically parses them so your function can use it. Parsed form data can be accessed through r.RequestFormData variable. For example if the payload fragment looks like this:
1
...
2
--------------------------5683f7544dff7b07
3
Content-Disposition: form-data; name="username"
4
​
5
John
6
--------------------------5683f7544dff7b07
7
...
Copied!
Then to get username value (which is John) you will need to:
1
-- import "json" package when working with JSON
2
local json = require("json")
3
​
4
-- values can be accessed through 'r.RequestFormData' object. Since
5
-- there can be multiple values for each key, you also need to
6
-- specify that it's the first element of the list:
7
local username = r.RequestFormData.username[1]
8
local first_name = r.RequestFormData.first_name[1]
9
​
10
-- transforming form data into JSON
11
local json_payload = {
12
username = username,
13
first_name = first_name
14
}
15
​
16
local encoded_payload, err = json.encode(json_payload)
17
if err then error(err) end
18
​
19
r:SetRequestBody(encoded_payload)
Copied!
Copy link