Sample code for 30+ languages & platforms
Lua

Send a Multipart REST Request

See more REST Examples

Demonstrates Rest.FullRequestMultipart, which sends a complete multipart request using the parts configured on the object, then returns the response body as text.

Background. Each multipart part is built by selecting it with the part selector, adding its header fields, and setting its body. FullRequestMultipart then assembles and sends all configured parts as a single multipart request.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local rest = chilkat.Rest.new()
local bTls = true
local bAutoReconnect = true
local success = rest:connect("example.com", 443, bTls, bAutoReconnect)
if not success then
    print(rest.last_error_text)
    return
end

-- Configure a multipart request part before sending.  PartSelector selects the part being built,
-- and the header fields and body apply to that part.
rest.part_selector = "1"
rest:add_header("Content-Type", "text/plain")
rest:add_header("Content-Disposition", "form-data; name=\"field1\"")
success = rest:set_multipart_body_string("value1")
if not success then
    print(rest.last_error_text)
    return
end

-- Send the multipart request using the configured parts.  The response body is returned as text.
local responseText = rest:full_request_multipart("POST", "/api/upload")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

print(responseText)