file-type-filter
A stream filter that allows only specified file types to pass, blocking all the others. The file type is detected using file-type.
Installation
npm install --save file-type-filter
Example
const FileTypeFilter = // Create a filter that allows only JPEGs to passconst filter = 'image/jpeg' // Will succeedfs // Will fail (block)fsfilter
File Type Specification
File types that are allowed to pass are specified when a filter object is created, by passing an argument. The argument can be any of the following
- A string consisting of an allowed MIME type, for example
image/jpeg
- An array of strings of one or more allowed MIME types, for example
['application/zip', 'image/jpeg']
- A function, that receives the MIME type as a parameter and returns
true
if the file is allowed to pass.