I am trying to detect my uploaded file type. There are two files im uploading:
input.xls
And
input.ods
In node i run the following code:
var magic = new Magic(mmm.MAGIC_MIME_TYPE);
magic.detectFile(req.filePath, function(err, result) {
if (err) {
waterfallCallback(customError.invalidInputMessage('File not uploaded'));
return;
}
var fileType;
var error;
switch(result) {
case 'text/plain':
case 'text/csv':
case 'application/csv':
fileType = 'csv';
break;
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel':
fileType = 'excel';
break;
case 'application/vnd.ms-office':
error = customError.invalidInputMessage('Fileformat not supported');
break;
case 'application/vnd.oasis.opendocument.spreadsheet':
fileType = 'ods';
break;
default:
error = customError.invalidInputMessage('Only xlsx, xls and csv file types are supported');
return;
}
waterfallCallback(error, fileType);
});
Debugging this code says that the file type is :
inode/x-empty
Can anyone tell me why this is happening?