Recall & Review
beginner
What is the purpose of the
multer middleware in Express?Multer is used to handle file uploads in Express apps. It processes incoming files and stores them temporarily or permanently.
Click to reveal answer
beginner
How do you configure multer to accept a single file upload with the field name 'avatar'?
Use
upload.single('avatar') where upload is the multer instance. This tells multer to expect one file with the field name 'avatar'.Click to reveal answer
beginner
What does
req.file contain after a successful single file upload?req.file holds information about the uploaded file like its original name, size, encoding, and the path where it was saved.Click to reveal answer
intermediate
Why is it important to handle errors when uploading files in Express?
Errors can happen if the file is too large, the wrong type, or the upload fails. Handling errors helps keep the app stable and informs users what went wrong.
Click to reveal answer
intermediate
What is a simple way to limit the size of uploaded files using multer?
Set the
limits.fileSize option in multer configuration to restrict the maximum file size allowed.Click to reveal answer
Which middleware is commonly used for handling single file uploads in Express?
✗ Incorrect
Multer is designed specifically for handling multipart/form-data, which is used for file uploads.
What does
upload.single('photo') do in an Express route?✗ Incorrect
It tells multer to expect a single file upload with the field name 'photo'.
Where can you find the uploaded file's information after multer processes it?
✗ Incorrect
req.file contains the uploaded file's details for single file uploads.How can you limit the size of an uploaded file using multer?
✗ Incorrect
Multer's configuration allows setting
limits.fileSize to restrict file size.What happens if a file larger than the limit is uploaded with multer?
✗ Incorrect
Multer throws an error when the file size exceeds the limit, which should be handled properly.
Explain how to set up a simple Express route to handle a single file upload using multer.
Think about the steps from importing multer to accessing the file in the route.
You got /5 concepts.
Describe why handling errors during file upload is important and how you might do it in Express with multer.
Consider what can go wrong and how to keep the app stable.
You got /4 concepts.