S
S
Stopy2015-08-27 13:35:22
Node.js
Stopy, 2015-08-27 13:35:22

Multer, how to disable large file uploads?

No matter how much he tries, no matter what he does, in any case, he first downloads the entire file (at least 50GB), and only then checks the size and extension (and deletes it, as in my example)

multer({
  dest: './upload/',
  limits: {
    fileSize: 3*1024*1024
  },
  onFileUploadData: function(file, req, res) {
    if (file.size > 1024*1024*3) {
      return false; // Если файл не картинка, то file - вообще не выводиться, соответственно и размер не проверить
      console.log('limit');
    }
  },
  onFileUploadStart: function (file, req, res) {
    console.log('Upload started');
    var mime = file.mimetype;
    if (mime != 'image/jpeg' && mime != 'image/png') {
      res.end('Неправильный тип файла.');
      return false;
    }
  },
  onFileSizeLimit: function (file) {
    console.log('Failed: ', file.originalname);
    fs.unlink('./' + file.path);
  },
  onFileUploadComplete: function (file, req, res) {
    res.end('file uploaded');
    console.log('uploaded');
  }

});

What am I doing wrong? Or how can this problem be solved without multer?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stopy, 2015-08-27
@Stopy

in the comments to the question, the person suggested that before starting the download, check the content-length, and then parse the file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question