VidTube uses Cloudinary for all media storage — video files, thumbnails, user avatars, and cover images. When a user uploads a file, Multer saves it temporarily toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Pragyat-Nikunj/VidTube/llms.txt
Use this file to discover all available pages before exploring further.
./public/temp on the server; VidTube then streams it to Cloudinary, deletes the local copy, and stores the returned URL in MongoDB. You need a Cloudinary account before you can run any upload endpoints.
How VidTube uses Cloudinary
VidTube’s Cloudinary utility (src/utils/cloudinary.js) exposes two functions:
uploadOnCloudinary(localFilePath)— uploads a file from the local filesystem withresource_type: "auto", which lets Cloudinary auto-detect whether the file is an image or video. On success, the local file is deleted and the Cloudinary response object is returned. On failure, the local file is still deleted andnullis returned.deleteFromCloudinary(publicId)— removes a previously uploaded asset by its Cloudinary public ID. Used when a user updates their avatar or a video is deleted.
What gets stored
| Asset | Field name | Upload behavior |
|---|---|---|
| Video file | videoFile | Uploaded with resource_type: auto |
| Thumbnail | thumbnail | Uploaded with resource_type: auto |
| User avatar | avatar | Uploaded on register; old asset deleted when updated |
| Cover image | coverImage | Optional; uploaded on register if provided |
Set up Cloudinary
Create a free Cloudinary account
Go to cloudinary.com and sign up for a free account. No credit card is required to start.
Find your credentials
After signing in, open the Cloudinary Dashboard. At the top of the page you will see your:
- Cloud name — a unique identifier for your Cloudinary environment (e.g.,
my-cloud) - API key — a numeric key used to identify your account in API requests
- API secret — a private secret that authorizes writes, deletes, and signed uploads
Add the credentials to your `.env` file
Open your project’s Replace the values with the ones from your Cloudinary Dashboard.
.env file and add the three Cloudinary variables:Cloudinary’s free plan includes 25 credits per month and up to 1 GB of storage. A credit roughly corresponds to one transformation or one upload action. For development and light testing, the free plan is sufficient. Refer to the Cloudinary pricing page for details on paid plans.
Upload flow
Every file upload in VidTube follows this sequence:- The client sends a
multipart/form-datarequest. - Multer intercepts the request and saves the file to
./public/tempon the server disk. - The controller calls
uploadOnCloudinarywith the temporary file path. - Cloudinary receives the file, stores it, and returns a response containing the public URL and public ID.
- VidTube stores the URL and public ID in MongoDB, then deletes the local temp file.
null. The controller should handle this case and return a 500 error to the client.