How do you handle file uploads in an Express API?
Model answer
Use multer (or busboy) to parse multipart form data. Limit file size and count, check the MIME type and also the real content or extension, store files outside the web root with generated names (or in object storage such as S3), and never trust the original filename. Scan or process untrusted files, and serve them with safe headers.
Learn this topic
Build a REST API: Create, Read, Update and Delete Tasks in the course Node.js and Express: Build a Back End API from Scratch.
Sign in to add your own answer.