Repository URL to install this package:
|
Version:
3.12.2 ▾
|
import getFileNameAndExtension from './getFileNameAndExtension';
import mimeTypes from './mimeTypes';
// if type is set in the file object already, use that
// otherwise extract it from the file name (not the best)
export default function getFileType(file) {
var _file$info, _file$info2, _file$data, _getFileNameAndExtens;
if (!file) {
return null;
}
var type = file.type || file.mime || ((_file$info = file.info) === null || _file$info === void 0 ? void 0 : _file$info.type) || ((_file$info2 = file.info) === null || _file$info2 === void 0 ? void 0 : _file$info2.img_type) || ((_file$data = file.data) === null || _file$data === void 0 ? void 0 : _file$data.type);
if (type) {
return type;
}
var fileExtension = file.name ? (_getFileNameAndExtens = getFileNameAndExtension(file.name).extension) === null || _getFileNameAndExtens === void 0 ? void 0 : _getFileNameAndExtens.toLowerCase() : null;
if (fileExtension && mimeTypes[fileExtension]) {
// else, see if we can map extension to a mime type
return mimeTypes[fileExtension];
}
// if all fails, fall back to a generic byte stream type
return 'application/octet-stream';
}