diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index b2fbbafb..fd45392e 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -103,11 +103,13 @@ export const uniqueId = (len: number = 10): string => { */ export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Promise => { let type; + try { type = await fromBuffer(file); } catch(e) { console.warn("An exception occurred while processing the buffer:", e.message); } + if (name && name.indexOf('.') > -1) { const mime = extensionToMime(name); @@ -115,6 +117,7 @@ export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Prom return mime; } } + const excludedMimetypes = ['text/plain', 'application/octet-stream', 'application/x-ms', 'application/x-msi', 'application/zip']; if (type && excludedMimetypes.indexOf(type.mime) === -1) { @@ -137,6 +140,7 @@ export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Prom return type.mime; } + return 'application/octet-stream'; }; /**