Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@types/formidable
Advanced tools
@types/formidable provides TypeScript type definitions for the formidable package, which is used for parsing form data, especially file uploads.
Parsing Form Data
This feature allows you to parse incoming form data, including file uploads. The `form.parse` method takes a request object and a callback function that handles the parsed fields and files.
const formidable = require('formidable');
const form = new formidable.IncomingForm();
form.parse(req, (err, fields, files) => {
if (err) {
console.error(err);
return;
}
console.log('Fields:', fields);
console.log('Files:', files);
});
Handling File Uploads
This feature allows you to handle file uploads by specifying an upload directory. The `uploadDir` property sets the directory where uploaded files will be stored.
const formidable = require('formidable');
const form = new formidable.IncomingForm();
form.uploadDir = '/path/to/upload/directory';
form.parse(req, (err, fields, files) => {
if (err) {
console.error(err);
return;
}
console.log('Uploaded files:', files);
});
Customizing File Uploads
This feature allows you to customize the file upload process. The `fileBegin` event is triggered when a file upload starts, allowing you to set a custom file path.
const formidable = require('formidable');
const form = new formidable.IncomingForm();
form.on('fileBegin', (name, file) => {
file.path = '/custom/path/' + file.name;
});
form.parse(req, (err, fields, files) => {
if (err) {
console.error(err);
return;
}
console.log('Custom file path:', files);
});
Multer is a middleware for handling `multipart/form-data`, which is primarily used for uploading files. It is similar to formidable but is designed to work specifically with Express.js. Multer is more modern and integrates seamlessly with Express, making it a popular choice for file uploads in Express applications.
Busboy is a fast and low-level library for parsing `multipart/form-data` used for file uploads. It is similar to formidable but offers more control and is more performant. Busboy is often used in scenarios where performance is critical and fine-grained control over file uploads is required.
Multiparty is another library for parsing `multipart/form-data`, similar to formidable. It is known for its simplicity and ease of use. Multiparty is a good alternative if you need a straightforward solution for handling file uploads without the additional features provided by formidable.
npm install --save @types/formidable
This package contains type definitions for formidable (https://github.com/node-formidable/formidable).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/formidable.
These definitions were written by Wim Looman, and Martin Badin.
FAQs
TypeScript definitions for formidable
The npm package @types/formidable receives a total of 335,009 weekly downloads. As such, @types/formidable popularity was classified as popular.
We found that @types/formidable 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.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.