Sunday, 23 April 2017

Node.js fs.stat [TypeError: path must be a string] on passing Buffer

According to documentation for fs.stat here, stat function can accept a string path to a file OR a buffer.

But when I passed a Buffer, I am getting an error:

[TypeError: path must be a string]

Below is the code.

exports.importNow = function (req, res) {
try {
      fs.stat( req.files.csv.buffer, function (err, stat) {
          if( err == null ) {
              console.log(2);
              return resolve();
          } else {
              console.log(3);
              return reject( [validation_errors.FILE_DOES_NOT_EXIST, err] );
          }
      });

    } catch ( err ) {
      console.log(5);
      console.log(err);
      return reject( [validation_errors.FILE_DOES_NOT_EXIST, err] );
    }
}

Cann anybody please help me find the reason? Or am I missing anything? Thank you.



via Katti

No comments:

Post a Comment