Skip to content

Commit f5d5cdb

Browse files
sethk4783SethK
and
SethK
authored
fix:Added fallback type as application/octet-stream (#555)
Co-authored-by: SethK <[email protected]>
1 parent 518cdaf commit f5d5cdb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/lib/utils/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,21 @@ export const uniqueId = (len: number = 10): string => {
103103
*/
104104
export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Promise<string> => {
105105
let type;
106+
106107
try {
107108
type = await fromBuffer(file);
108109
} catch(e) {
109110
console.warn("An exception occurred while processing the buffer:", e.message);
110111
}
112+
111113
if (name && name.indexOf('.') > -1) {
112114
const mime = extensionToMime(name);
113115

114116
if (mime) {
115117
return mime;
116118
}
117119
}
120+
118121
const excludedMimetypes = ['text/plain', 'application/octet-stream', 'application/x-ms', 'application/x-msi', 'application/zip'];
119122

120123
if (type && excludedMimetypes.indexOf(type.mime) === -1) {
@@ -137,6 +140,7 @@ export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Prom
137140
return type.mime;
138141
}
139142

143+
return 'application/octet-stream';
140144
};
141145

142146
/**

0 commit comments

Comments
 (0)