Windsurf storage

Multer File Upload Crashing in Windsurf App

File uploads in your Windsurf-generated app crash with multer errors. The server either runs out of memory processing large files, throws LIMIT_UNEXPECTED_FILE errors, or crashes silently when handling multipart form data.

Multer is the most common file upload middleware for Node.js/Express apps, and Cascade frequently generates upload endpoints using it. However, the generated configuration often has missing error handling, incorrect field names, or no memory limits, causing production crashes.

The issue typically appears when users upload files larger than expected, when multiple files are uploaded simultaneously, or when the form field name doesn't match the multer configuration.

Error Messages You Might See

MulterError: LIMIT_UNEXPECTED_FILE Error: LIMIT_FILE_SIZE JavaScript heap out of memory PayloadTooLargeError: request entity too large Error: Unexpected field
MulterError: LIMIT_UNEXPECTED_FILEError: LIMIT_FILE_SIZEJavaScript heap out of memoryPayloadTooLargeError: request entity too largeError: Unexpected field

Common Causes

  • No file size limit configured — Multer defaults to no limit, so a large upload loads entirely into memory and crashes the Node.js process
  • Field name mismatch — The form sends the file as 'image' but multer.single() expects 'file', or vice versa
  • Missing error handling middleware — Multer errors aren't caught, causing unhandled exceptions that crash the server
  • MemoryStorage on large files — Cascade used multer.memoryStorage() instead of diskStorage(), loading entire files into RAM
  • No file type validation — The fileFilter is missing, allowing any file type to be processed
  • Concurrent upload overload — No limit on simultaneous uploads, exhausting server memory with multiple large files

How to Fix It

  1. Add file size limits — Configure multer with limits: { fileSize: 5 * 1024 * 1024 } (5MB) or whatever maximum your app needs
  2. Switch to disk storage — Replace multer.memoryStorage() with multer.diskStorage() for files larger than 1-2MB to avoid memory exhaustion
  3. Match field names — Check that your HTML form input name attribute matches the string in multer.single('fieldname') or multer.fields()
  4. Add multer error handling — Add an Express error handler that catches MulterError instances and returns proper 400/413 responses
  5. Validate file types — Add a fileFilter function that checks MIME types and rejects unsupported formats before processing
  6. Stream to cloud storage — For production apps, use multer-s3 or multer-google-storage to stream uploads directly to cloud storage without local disk or memory

Real developers can help you.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Why does my server crash instead of returning an error?

Multer errors need explicit error handling. Without it, unhandled exceptions crash the Node.js process. Add a middleware after your route that checks for MulterError and sends a proper HTTP 400 or 413 response.

Should I use memoryStorage or diskStorage?

Use memoryStorage only for small files (under 1-2MB) like profile avatars. For larger files, use diskStorage or stream directly to cloud storage. MemoryStorage loads the entire file into RAM, which crashes your server under load.

Related Windsurf Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help