The LMS Backend handles two types of media uploads: course thumbnails (images) and lecture videos. Both follow the same pipeline — Multer writes the incoming file to a temporary directory on disk, the controller then reads that file path and streams it to Cloudinary, and the returned Cloudinary URL is persisted on the database document. Cloudinary URLs are what you receive back in API responses.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Pragyat-Nikunj/Learning-Management-System-backend/llms.txt
Use this file to discover all available pages before exploring further.
Upload pipeline
Multipart request arrives
Your client sends a
multipart/form-data request. Multer is applied as route-level middleware using upload.single(fieldName), where fieldName is either "thumbnail" or "video" depending on the endpoint.Multer writes to disk
The Multer instance is configured with
dest: "upload", which writes the uploaded file to a local upload/ directory as a temporary file. The file’s path is available on req.file.path.utils/multer.js
Controller uploads to Cloudinary
The controller calls
uploadMedia(req.file.path). Cloudinary’s SDK reads the temp file, uploads it with resource_type: "auto" (which automatically detects images and videos), and returns an upload response object.utils/cloudinary.js
Supported file types and field names
Cloudinary’sresource_type: "auto" means the SDK infers the type from the file content rather than relying on the MIME type or extension. In practice:
| Endpoint | Field name | Expected content |
|---|---|---|
POST /api/v1/courses | thumbnail | Image (JPEG, PNG, WebP, etc.) |
PATCH /api/v1/courses/:courseId | thumbnail | Image (JPEG, PNG, WebP, etc.) |
POST /api/v1/courses/:courseId/lectures | video | Video (MP4, MOV, WebM, etc.) |
PATCH /api/v1/user/profile | avatar | Image (JPEG, PNG, WebP, etc.) |
Multer does not enforce a file size limit or MIME type filter in the current configuration. Cloudinary’s own upload limits apply. Cloudinary free-tier accounts have a 10 MB image limit and a 100 MB video limit per upload.
Uploading a course thumbnail
Creating a course requiresisAuthenticated middleware and a multipart/form-data body with a thumbnail file field alongside the course text fields:
thumbnail field:
Adding a lecture with a video
Adding a lecture to an existing course usesupload.single("video"). Send the video file under the video field:
Updating or replacing media
When you update a course (PATCH /api/v1/courses/:courseId) or a user avatar (PATCH /api/v1/user/profile) with a new file, the controller deletes the old Cloudinary asset before uploading the replacement. Deletion uses the asset’s public_id:
utils/cloudinary.js