Node Js: How To Get File Signature Headers Instead Of Mime-type?
I downloaded this module for my node js project, and it seems to work fine up to a certain point. If you console.log(mime.lookup(pathToFile)); it returns the correct file type that
Solution 1:
Try using file-type.
Detect the file type of a Buffer/Uint8Array
The file type is detected by checking the magic number of the buffer.
const readChunk = require('read-chunk'); // npm install read-chunk const fileType = require('file-type');
const buffer = readChunk.sync('unicorn.png', 0, 262);
fileType(buffer);
//=> {ext: 'png', mime: 'image/png'}
It requires to read the first 262 bytes. Check the supported extensions on the page
Post a Comment for "Node Js: How To Get File Signature Headers Instead Of Mime-type?"