https://github.com/kong/lua-multipart
Multipart Parser for Lua
https://github.com/kong/lua-multipart
Last synced: 5 months ago
JSON representation
Multipart Parser for Lua
- Host: GitHub
- URL: https://github.com/kong/lua-multipart
- Owner: Kong
- License: mit
- Created: 2015-04-14T02:00:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T10:11:37.000Z (over 2 years ago)
- Last Synced: 2025-03-31T18:41:57.863Z (6 months ago)
- Language: Lua
- Size: 39.1 KB
- Stars: 58
- Watchers: 40
- Forks: 23
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-multipart [](https://travis-ci.org/Kong/lua-multipart)
A Lua library to parse and edit `multipart/form-data` data.
# Usage
```lua
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.