4

I have a controller in sails js which takes care of uploading images to s3. Everything works fine and image is uploaded to s3 assuming that only one file was sent for the param "image" (which I can access through req.file('image')). I want to know, how to validate, that only one file ( input type="file" ) is sent and uploaded and not multiple ( input type="file" multiple ) files.

Fact: Multiple files are getting uploaded successfully, but the I can not see multiple files in req.file('image')._files

Utkarsh51
  • 63
  • 3

1 Answers1

0

As per sails documentation, You can get the number of files uploaded like this:

req.file('avatar').upload(function (err, files){
 if (err) return res.serverError(err);
  return res.json({
  message: files.length + ' file(s) uploaded successfully!',
  files: files
 });
});
Sapna Jindal
  • 412
  • 3
  • 11
  • But the issue here is that you can't find the number of files *before* uploading them. So a user can send 500 files and overload your server's storage before you realize that the user has uploaded a lot of files – TheLebDev Nov 01 '19 at 10:20