
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
validate-image-type
Advanced tools
Check the image file of a Buffer/Uint8Array that matched expected image MIME-type.
Check the image file of a Buffer/Uint8Array that matched expected image MIME-type.
This library check the file contents instead of file extensions using following:
Install with npm:
npm install validate-image-type
import { validateMIMEType } from "validate-image-type";
const result = await validateMIMEType("./image.png", {
allowMimeTypes: ['image/jpeg', 'image/gif', 'image/png', 'image/svg+xml']
});
if (!result.ok) {
console.error(result.error);
return;
}
console.log("This image is supported!");
See following document about MimeType.
Basic images file types and SVG(image/svg+xml).
"jpg",
"png",
"gif",
"webp",
"flif",
"cr2",
"tif",
"bmp",
"jxr",
"psd",
"ico",
"bpg",
"jp2",
"jpm",
"jpx",
"heic",
"cur",
"dcm",
"svg"
Integration with Multer middleware.
const multer = require('multer');
const temp_local_img_dir = path.join(__dirname, `/.temp_local_img_dir`);
const upload = multer({ dest: temp_local_img_dir });
const asyncWrapper = fn => {
return (req, res, next) => {
return fn(req, res, next).catch(next);
}
};
app.post(
'/upload',
upload.single('image'),
asyncWrapper(async (req, res, next) => {
const validationResult = await validateMIMEType(req.file.path, {
originalFilename: req.file.originalname,
allowMimeTypes: ['image/jpeg', 'image/gif', 'image/png', 'image/svg+xml'],
});
console.log('validationResult', validationResult);
if (!validationResult.ok) {
return res.send(400);
}
// uploading task
// ...
})
);
See Releases page.
Install devDependencies and Run npm test:
npm test
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
git checkout -b my-new-featuregit commit -am 'Add some feature'git push origin my-new-featureMIT © azu
FAQs
Check the image file of a Buffer/Uint8Array that matched expected image MIME-type.
The npm package validate-image-type receives a total of 2,288 weekly downloads. As such, validate-image-type popularity was classified as popular.
We found that validate-image-type 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.