Complete the code to import Multer in an Express app.
const multer = require('[1]');
You need to import the 'multer' package to use it as middleware.
Complete the code to create a Multer instance with default storage.
const upload = multer({ [1] });The 'dest' option tells Multer where to save uploaded files.
Fix the error in the route to use Multer middleware for single file upload named 'avatar'.
app.post('/profile', upload.[1]('avatar'), (req, res) => { res.send('File uploaded'); });
The 'single' method handles uploading one file with the given field name.
Fill both blanks to configure Multer to accept multiple files named 'photos' with a max count of 3.
app.post('/upload', upload.[1]('photos', [2]), (req, res) => { res.send('Multiple files uploaded'); });
The 'array' method accepts multiple files with the given field name and max count.
Fill all three blanks to create a Multer storage engine that saves files with original name in 'uploads/' folder.
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] });This sets the destination folder to 'uploads/', uses the original file name, and assigns the storage engine to Multer.