expressjs / multer

Node.js middleware for handling `multipart/form-data`.
MIT License
11.61k stars 1.06k forks source link

multiple files upload #275

Open ghost opened 8 years ago

ghost commented 8 years ago

In fileFileter tried to handle custom errors on file extensions, on fileName length - and got in error from multer.

If I have an error I do so

if (!new RegExp(config.allowedFileExt + "$").test(file.originalname)) {
    err = new Error(file.originalname + ": File should have *.xlsx extension");
    return cb(err);
} else if (file.originalname.length > config.maxFileNameLength) {
    err = new Error(file.originalname + ": Filename shouldn't exceed 64 characters");
    return cb(err);
} else {
    cb(null, true);
}

The main thing is if the first file is valid and after that we have two errors I end up with the error from the code disk.js:

DiskStorage.prototype._removeFile = function _removeFile (req, file, cb) {
  var path = file.path

  delete file.destination
  delete file.filename
  delete file.path

  fs.unlink(path, cb)
}

which try to remove twice(the count of errors) that one valid first saved file. In first case it do it right, but in second it cannot find the file.path (it was removed in previous call) and throw error.

gireeshpunathil commented 5 years ago

@ViktorSoroka is this still an issue ?

ViktorSoroka07 commented 5 years ago

Have not tested it since then.