0
0
Expressframework~10 mins

Multer middleware setup in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import Multer in an Express app.

Express
const multer = require('[1]');
Drag options to blanks, or click blank then click option'
Amulter
Bexpress
Cbody-parser
Dcors
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'multer' in the require statement.
Forgetting to import multer before using it.
2fill in blank
medium

Complete the code to create a Multer instance with default storage.

Express
const upload = multer({ [1] });
Drag options to blanks, or click blank then click option'
Afolder: 'uploads/'
Bstorage: 'uploads/'
Cpath: 'uploads/'
Ddest: 'uploads/'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'storage' with a string instead of a storage engine.
Using 'path' or 'folder' which are not valid Multer options.
3fill in blank
hard

Fix the error in the route to use Multer middleware for single file upload named 'avatar'.

Express
app.post('/profile', upload.[1]('avatar'), (req, res) => {
  res.send('File uploaded');
});
Drag options to blanks, or click blank then click option'
Afiles
Barray
Csingle
Dfields
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'files' which is not a Multer method.
Using 'array' or 'fields' when only one file is expected.
4fill in blank
hard

Fill both blanks to configure Multer to accept multiple files named 'photos' with a max count of 3.

Express
app.post('/upload', upload.[1]('photos', [2]), (req, res) => {
  res.send('Multiple files uploaded');
});
Drag options to blanks, or click blank then click option'
Aarray
B3
C5
Dsingle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'single' instead of 'array' for multiple files.
Setting max count to a wrong number or missing it.
5fill in blank
hard

Fill all three blanks to create a Multer storage engine that saves files with original name in 'uploads/' folder.

Express
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, '[1]');
  },
  filename: function (req, file, cb) {
    cb(null, file.[2]);
  }
});

const upload = multer({ storage: [3] });
Drag options to blanks, or click blank then click option'
Auploads/
Boriginalname
Cstorage
Dfilename
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'filename' instead of 'originalname' for the file name.
Passing the wrong variable to Multer storage option.