Commit a31d34d5 authored by Sudheer's avatar Sudheer Committed by Elias Nahum
Browse files

[MM-13147] Fix for file_upload crash when mimeTypesSuffix is not present (#2074)

* MM-13147 Fix for file_upload crash for certain mimeTypes

* Update utils/file_utils.jsx
parent 6713fa07
......@@ -64,20 +64,25 @@ export function getFileTypeFromMime(mimetype) {
const mimeTypeSplitBySlash = mimetype.split('/');
const mimeTypePrefix = mimeTypeSplitBySlash[0];
const mimeTypeSuffix = mimeTypeSplitBySlash[1];
if (mimeTypePrefix === 'video') {
return 'video';
} else if (mimeTypePrefix === 'audio') {
return 'audio';
} else if (mimeTypePrefix === 'image') {
return 'image';
} else if (mimeTypeSuffix === 'pdf') {
return 'pdf';
} else if (mimeTypeSuffix.includes('vnd.ms-excel') || mimeTypeSuffix.includes('spreadsheetml') || mimeTypeSuffix.includes('vnd.sun.xml.calc') || mimeTypeSuffix.includes('opendocument.spreadsheet')) {
return 'spreadsheet';
} else if (mimeTypeSuffix.includes('vnd.ms-powerpoint') || mimeTypeSuffix.includes('presentationml') || mimeTypeSuffix.includes('vnd.sun.xml.impress') || mimeTypeSuffix.includes('opendocument.presentation')) {
return 'presentation';
} else if ((mimeTypeSuffix === 'msword') || mimeTypeSuffix.includes('vnd.ms-word') || mimeTypeSuffix.includes('officedocument.wordprocessingml') || mimeTypeSuffix.includes('application/x-mswrite')) {
return 'word';
}
if (mimeTypeSuffix) {
if (mimeTypeSuffix === 'pdf') {
return 'pdf';
} else if (mimeTypeSuffix.includes('vnd.ms-excel') || mimeTypeSuffix.includes('spreadsheetml') || mimeTypeSuffix.includes('vnd.sun.xml.calc') || mimeTypeSuffix.includes('opendocument.spreadsheet')) {
return 'spreadsheet';
} else if (mimeTypeSuffix.includes('vnd.ms-powerpoint') || mimeTypeSuffix.includes('presentationml') || mimeTypeSuffix.includes('vnd.sun.xml.impress') || mimeTypeSuffix.includes('opendocument.presentation')) {
return 'presentation';
} else if ((mimeTypeSuffix === 'msword') || mimeTypeSuffix.includes('vnd.ms-word') || mimeTypeSuffix.includes('officedocument.wordprocessingml') || mimeTypeSuffix.includes('application/x-mswrite')) {
return 'word';
}
}
return 'other';
......
......@@ -104,6 +104,10 @@ describe('FileUtils.canUploadFiles', () => {
it('mime type for unknown file format', () => {
assert.equal(getFileTypeFromMime('application/unknownFormat'), 'other');
});
it('mime type for no suffix', () => {
assert.equal(getFileTypeFromMime('asdasd'), 'other');
});
});
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment