Skip to content

Kong/lua-multipart

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

lua-multipart Build Status

A Lua library to parse and edit multipart/form-data data.

Usage

local Multipart = require("multipart")

-- Initialize with a body
local multipart_data = Multipart(body, content_type_header)

-- Reading parameters
local parameter = multipart_data:get("param-name")

parameter.value -- The value
parameter.headers -- A table with the headers associated with the parameter

-- Reading all values of `files` part
local files = multipart_data:get_as_array("files")

-- Setting a new parameter
multipart_data:set_simple("some-param-name", "some-value")

-- Deleting a parameter
multipart_data:delete("param-name")

-- Setting a file
multipart_data:set_simple("name", "some-value", "filename", "content_type")

-- Get a multipart/form-data representation of the object
local body = multipart_data:tostring()

-- Get all the parameters in a Lua table, in the form of {param_name = param_value}
local t = multipart_data:get_all()

-- Get all the parameters in a Lua table, in the form of {param_name = param_value} where param_value is array
local t = multipart_data:get_all_as_arrays()

-- Get all the parameters in a Lua table, in the form of {param_name = param_value} where param_value is string or array
local t = multipart_data:get_all_with_arrays()

Contribute

This library is a work in progress, pull-requests are welcomed.