Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
express-fileupload-validator
Advanced tools
Readme
Validator for express-fileupload package.
npm i express-fileupload
In order to use this package you need to use express alongside express-fileupload.
const express = require('express');
const expressFileupload = require('express-fileupload');
const app = express();
// ...
app.use(expressFileupload());
app.listen(8080);
const express = require('express');
const { ExpressFileuploadValidator } = require('express-fileupload-validator');
// You can export it to reuse the same validations.
const expressFileuploadValidator = new ExpressFileuploadValidator({
minCount: 2,
maxCount: 8,
allowedExtensions: ['jpg', 'png', 'gif'],
allowedMimetypes: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'],
maxSize: '20MB',
});
const router = Router();
router.post('/upload-images', (req, res) => {
if (!req.files || !req.files.images) {
// We didn't get any files at all here..
}
try {
expressFileuploadValidator.validate(req.files.images); // Validate the file or files.
// Everything ok we can save the files safely now :)
} catch (e) {
console.log(e.errors); // Validation error messages...
}
});
Type: object
In addition, you can specify the below options.
Type: number
Default: -1
(no limit)
The number of minimum files.
Type: number
Default: -1
(no limit)
The number of maximum files.
Type: string | number
Default: -1
(no limit)
The minimum size per file.
Can be formatted size, for example: 2MB
, 5GB
and etc.
Can be size in bytes, for example: 6291456
which is 6MB.
Type: string | number
Default: -1
(no limit)
The maximum size per file.
Can be formatted size, for example: 2MB
, 5GB
and etc.
Can be size in bytes, for example: 6291456
which is 6MB.
Type: string[]
Default: []
List of allowed file extensions, for example: ['jpg', 'png']
.
Type: string[]
Default: []
List of disallowed file extensions, for example: ['jpg', 'png']
.
Type: string[]
Default: []
List of allowed file mimetypes, for example: ['image/jpg', 'image/png']
.
Type: string[]
Default: []
List of disallowed file mimetypes, for example: ['image/jpg', 'image/png']
.
Type: bool
Default: true
Will decide if to abort as soon as possible, that means you will always gets the first error.
If abortEarly is false
you will get all collected files errors.
You can specify object with your custom error messages. Please notice you need to keep the placeholders {} to keep the error messages clean.
const expressFileuploadValidator = new ExpressFileuploadValidator({}, {
minCount: 'Too few files, minimum {0} are expected but {1} are given',
maxCount: 'Too many files, maximum {0} are allowed but {1} are given',
minSize: 'Minimum expected size for file {0} is {1} but {2} detected',
maxSize: 'Maximum allowed size for file {0} is {1} but {2} detected',
allowedExtensions:
'File {0} has an incorrect extension of {1}, allowed extensions are: {2}',
disallowedExtensions:
'File {0} has an incorrect extension of {1}, disallowed extensions are: {2}',
allowedMimetypes:
'File {0} has an incorrect mimetype of {1}, allowed mimetypes are: {2}',
disallowedMimetypes:
'File {0} has an incorrect mimetype of {1}, disallowed mimetypes are: {2}',
});
Throws ExpressFileuploadValidatorErrors
if there are errors.
FAQs
Validator for express-fileupload package
The npm package express-fileupload-validator receives a total of 2 weekly downloads. As such, express-fileupload-validator popularity was classified as not popular.
We found that express-fileupload-validator 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
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.