Challenge - 5 Problems
File Storage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
Understanding file storage behavior in Express with multer
Consider an Express app using multer middleware to handle file uploads. If multer is configured with
storage: multer.memoryStorage(), what happens to the uploaded file data?Express
const multer = require('multer'); const upload = multer({ storage: multer.memoryStorage() }); app.post('/upload', upload.single('file'), (req, res) => { console.log(req.file.buffer); res.send('File received'); });
Attempts:
2 left
💡 Hint
Think about where memoryStorage keeps the file data.
✗ Incorrect
When using multer.memoryStorage(), multer stores the uploaded file data in RAM as a Buffer. This buffer is accessible in req.file.buffer. No file is saved on disk.
❓ component_behavior
intermediate2:00remaining
Behavior of multer.diskStorage in Express
When multer is configured with
storage: multer.diskStorage(), what is true about the uploaded files?Express
const multer = require('multer'); const storage = multer.diskStorage({ destination: (req, file, cb) => cb(null, './uploads'), filename: (req, file, cb) => cb(null, file.originalname) }); const upload = multer({ storage }); app.post('/upload', upload.single('file'), (req, res) => { console.log(req.file.path); res.send('File saved to disk'); });
Attempts:
2 left
💡 Hint
Disk storage means saving files on your server's hard drive.
✗ Incorrect
Using multer.diskStorage() saves the uploaded file physically on disk in the specified folder. The file path is available in req.file.path.
📝 Syntax
advanced2:00remaining
Identifying error in multer memoryStorage usage
Which option will cause a runtime error when trying to access the uploaded file's data in an Express route using multer with memoryStorage?
Express
const multer = require('multer'); const upload = multer({ storage: multer.memoryStorage() }); app.post('/upload', upload.single('file'), (req, res) => { // Access file data here });
Attempts:
2 left
💡 Hint
memoryStorage does not save files on disk, so some properties are missing.
✗ Incorrect
When using memoryStorage, req.file.path is undefined because the file is not saved on disk. Accessing it causes a runtime error.
❓ state_output
advanced2:00remaining
Comparing memory usage between diskStorage and memoryStorage
In an Express app handling large file uploads, what is a key difference in server memory usage between multer's diskStorage and memoryStorage?
Attempts:
2 left
💡 Hint
Think about where the file data lives during upload.
✗ Incorrect
memoryStorage keeps the entire file in RAM, increasing memory usage. diskStorage writes files to disk, reducing RAM usage but using disk space.
🔧 Debug
expert2:00remaining
Debugging file upload failure with multer diskStorage
An Express app uses multer.diskStorage to save uploaded files to './uploads'. However, uploads fail silently and no files appear in the folder. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check if the folder exists and can be written to by the server.
✗ Incorrect
If the destination folder does not exist or the server lacks permission to write there, multer cannot save files, causing silent failures.