Buffer.from('base64here');
await FileType.fromBuffer('bufferhere');
const decodeBase64Img = (base64String) => {
const matches = base64String.match(/^data:([A-Za-z-+/]+);base64,(.+)$/),
obj = {};
if (matches.length !== 3) {
return new Error('Invalid input string');
}
const [, extension, base64] = matches;
obj.type = extension;
obj.buffer = Buffer.from(base64, 'base64');
return obj;
// Based on: https://stackoverflow.com/Questions/20267939/Nodejs-Write-Base64-Image-File
};
await FileType.fromBuffer(decodeBase64Img('base64').buffer);