0

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?

Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
  • Are your files empty? – mscdex Mar 30 '16 at 12:45
  • @mscdex no they have 3 rows of data – Marc Rasmussen Mar 30 '16 at 13:48
  • Is it possible the file isn't (completely) written when you go to check the uploaded file? Did you try running this same code locally in isolation with the same file (outside of the upload scenario to make sure there is no race condition)? – mscdex Mar 30 '16 at 13:50
  • @mscdex i assume this is the issue ive posted another question regarding this issue: http://stackoverflow.com/questions/36312637/node-next-is-called-before-end-of-stream – Marc Rasmussen Mar 30 '16 at 15:01

0 Answers0