multer set file size limit code example

Example 1: php get size of file

$fileSizeInBytes=filesize("/path/to/myfile.txt");

Example 2: how to limit the file size in multer

var upload = multer({
  storage: storage,
  limits: { fileSize: maxSize } // filesize in bytes

}).single('bestand');

Example 3: how to set file type and size in multer

var multer = require('multer')
var upload = multer().single('avatar')

app.post('/profile', function (req, res) {
  upload(req, res, function (err) {
    if (err instanceof multer.MulterError) {
      // A Multer error occurred when uploading.
    } else if (err) {
      // An unknown error occurred when uploading.
    }

    // Everything went fine.
  })
})

Tags:

Php Example