Handle image and file uploads professionally with Multer and Cloudinary — including transformation, compression, and storage.

Abdur Razzak
Full-Stack Web Developer
Storing uploaded files on your own server creates maintenance headaches — disk space, backups, CDN delivery. Cloudinary is a managed media cloud that handles storage, transformation, and CDN delivery with a generous free tier.
Multer is an Express middleware that parses multipart/form-data requests and makes file buffers or temporary files available on req.file. Use memoryStorage to keep files in memory and stream them directly to Cloudinary.
Use the Cloudinary Node.js SDK to upload from a buffer with upload_stream. Specify a folder, set quality auto and fetch_format auto to automatically serve the best format and quality for each browser.
When a user replaces their profile photo, delete the old one from Cloudinary using its public_id. Always store the public_id in your database alongside the URL so you can clean up orphaned assets without manual intervention.