Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@coolgk/formdata
Advanced tools
A http request form data parser (large file friendly) for 'application/json', 'application/x-www-form-urlencoded' and 'multipart/form-data'. It only parses form data when you ask for it.
a javascript / typescript module
npm install @coolgk/formdata
A http request form data parser (large file friendly) for 'application/json', 'application/x-www-form-urlencoded' and 'multipart/form-data'. It only parses form data when you ask for it.
Report bugs here: https://github.com/coolgk/node-utils/issues
<form method="POST" enctype="multipart/form-data">
<input type="text" name="name">
<input type="text" name="age">
<input type="file" name="photo">
<input type="file" name="photo">
<input type="file" name="id">
</form>
// express middleware
const app = require('express')();
const formdata = require('@coolgk/formdata');
app.use(formdata.express());
app.post('/id-only', async (request, response, next) => {
const post = await request.formdata.getData('id'); // upload 3 files but only parse 1, ignore others
console.log(post);
response.json(post);
// output
// {
// "name": "Tim",
// "age": "33",
// "id": {
// "error": null,
// "fieldname": "id",
// "filename": "test.txt",
// "encoding": "7bit",
// "mimetype": "text/plain",
// "size": 13,
// "path": "/tmp/151605931497716067xZGgxPUdNvoj"
// }
// }
});
app.post('/all-files', async (request, response, next) => {
const post = await request.formdata.getData(['id', 'photo']); // parse all files
console.log(post);
response.json(post);
// output
// {
// "name": "Tim",
// "age": "33",
// "photo": [
// {
// "error": null,
// "fieldname": "photo",
// "filename": "test.png",
// "encoding": "7bit",
// "mimetype": "image/png",
// "size": 604,
// "path": "/tmp/151605931497716067xZGgxPUdNvoj"
// },
// {
// "error": null,
// "fieldname": "photo",
// "filename": "test.svg",
// "encoding": "7bit",
// "mimetype": "image/svg+xml",
// "size": 2484,
// "path": "/tmp/151605931497916067EAUAa3yB4q42"
// }
// ],
// "id": {
// "error": null,
// "fieldname": "id",
// "filename": "test.txt",
// "encoding": "7bit",
// "mimetype": "text/plain",
// "size": 13,
// "path": "/tmp/151605931498016067zqZe6dlhidQ5"
// }
// }
});
app.listen(8888);
const { formData, express, getFormData, FormDataError } = require('@coolgk/formdata');
const http = require('http');
http.createServer(async (request, response) => {
const data = await getFormData(request, { fileFieldNames: ['id', 'photo'] });
// OR
// const formdata = formData(request);
// ... some middelware
// ... in some routes
// const data = formdata.getData(['id', 'photo']);
console.log(data);
response.end(JSON.stringify(data));
// {
// "name": "Tim",
// "age": "33",
// "photo": [
// {
// "error": null,
// "fieldname": "photo",
// "filename": "test.png",
// "encoding": "7bit",
// "mimetype": "image/png",
// "size": 604,
// "path": "/tmp/151605931497716067xZGgxPUdNvoj"
// },
// {
// "error": null,
// "fieldname": "photo",
// "filename": "test.svg",
// "encoding": "7bit",
// "mimetype": "image/svg+xml",
// "size": 2484,
// "path": "/tmp/151605931497916067EAUAa3yB4q42"
// }
// ],
// "id": {
// "error": null,
// "fieldname": "id",
// "filename": "test.txt",
// "encoding": "7bit",
// "mimetype": "text/plain",
// "size": 13,
// "path": "/tmp/151605931498016067zqZe6dlhidQ5"
// }
// }
}).listen(8888);
FAQs
A http request form data parser (large file friendly) for 'application/json', 'application/x-www-form-urlencoded' and 'multipart/form-data'. It only parses form data when you ask for it.
The npm package @coolgk/formdata receives a total of 2 weekly downloads. As such, @coolgk/formdata popularity was classified as not popular.
We found that @coolgk/formdata demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.