DEV Community

Manthan Ankolekar
Manthan Ankolekar

Posted on

πŸš€ Automate Media Uploads to Cloudinary with Node.js: A Complete Guide

Managing media uploads manually can be a pain β€” especially when you're dealing with hundreds of images and videos. Whether you're a content creator, developer, or business owner, storing media in the cloud should be fast, organized, and reliable.

That's where Cloudinary Uploader comes in.

Built with Node.js, this open-source tool automates the process of uploading images and videos from a local folder to Cloudinary. It supports batch processing, multi-format handling, retry logic, and more.

Let’s dive into how it works and how you can get started in minutes.


🌟 Why Use This Uploader?

Here’s what makes Cloudinary Uploader stand out:

  • πŸ”„ Bulk Upload: Upload dozens or even hundreds of media files in one go.
  • ☁️ Cloud Storage: Securely store media on Cloudinary.
  • 🧠 Smart Detection: Automatically detects and separates images from videos.
  • πŸ“¦ Batch Processing: Upload files in customizable batch sizes.
  • ♻️ Retry Mechanism: Automatically retries failed uploads.
  • πŸ“Š Detailed Summary: Get a clear report of success and failure rates.

βš™οΈ Features at a Glance

Feature Description
Supported Formats Images: PNG, JPG, GIF, SVG, WebP, etc.
Videos: MP4, AVI, MOV, etc.
Organized Uploads Uploads are organized into images/ and videos/ folders in Cloudinary
Retry Logic Configurable retry attempts for failed uploads
Batch Configuration Upload files in batches (default: 10 per batch)
CLI Monitoring Real-time progress updates in the terminal

πŸ“ Project Structure

cloudinary-uploader/
β”œβ”€β”€ images/           # Place your media files here
β”œβ”€β”€ index.js          # Main script
β”œβ”€β”€ .env              # Your Cloudinary credentials (not committed)
β”œβ”€β”€ .env.example      # Example for setting up your env file
β”œβ”€β”€ package.json      # Project metadata and dependencies
└── README.md         # Project documentation
Enter fullscreen mode Exit fullscreen mode

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/manthanank/cloudinary-uploader.git
cd cloudinary-uploader
Enter fullscreen mode Exit fullscreen mode

2. Install Dependencies

npm install
Enter fullscreen mode Exit fullscreen mode

3. Configure Environment Variables

Create a .env file based on the provided .env.example:

CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
Enter fullscreen mode Exit fullscreen mode

Find these credentials in your Cloudinary dashboard.


πŸ–ΌοΈ Uploading Media

  1. Place all your images and videos inside the images/ folder.
  2. Run the uploader:
npm start
Enter fullscreen mode Exit fullscreen mode

You’ll see real-time logs like:

πŸ“ Found 150 media files to upload
πŸ–ΌοΈ  Images: 120
πŸŽ₯ Videos: 30
βš™οΈ  Processing in batches of 10 files
πŸ”„ Retry attempts: 3
...
πŸŽ₯ Uploaded video1.mp4 (video): https://res.cloudinary.com/demo/video/upload/videos/video1.mp4
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ Customization Options

πŸ“ Batch Size & Retry Attempts

You can adjust these in index.js:

const BATCH_SIZE = 10;       // Upload 10 files per batch
const RETRY_ATTEMPTS = 3;    // Retry failed uploads 3 times
const RETRY_DELAY = 2000;    // Delay between retries (in ms)
Enter fullscreen mode Exit fullscreen mode

βž• Add More File Types

To support additional formats, modify the extension arrays:

const IMAGE_EXTENSIONS = [...];
const VIDEO_EXTENSIONS = [...];
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ Error Handling & Troubleshooting

Problem Solution
❌ Folder not found Ensure images/ exists
❌ Invalid credentials Check your .env file
❌ Upload failed Check file format, size, internet connection
❌ Resource type error Verify correct file extension

πŸ“Š Upload Summary

At the end of each run, you’ll see a detailed summary:

πŸ“Š Upload Summary:
πŸ–ΌοΈ  Images - βœ… Successful: 118, ❌ Failed: 2
πŸŽ₯ Videos - βœ… Successful: 30, ❌ Failed: 0
πŸ“ˆ Overall Success Rate: 98.7%
Enter fullscreen mode Exit fullscreen mode

πŸ” Security Best Practices

  • Never commit your .env file to version control
  • Store your credentials securely (e.g., use CI/CD secrets in production)
  • Cloudinary uses secure URLs by default for all media

πŸ“¦ Tech Stack

  • Node.js: Core runtime
  • Cloudinary SDK: Media upload API
  • dotenv: Load environment variables
  • fs & path: File system utilities

πŸ§‘β€πŸ’» Contributing

Want to improve this project?

  1. Fork the repo
  2. Create a new feature branch
  3. Commit and push your changes
  4. Submit a pull request πŸš€

πŸ“˜ Final Thoughts

If you're tired of dragging and dropping files into a web dashboard, Cloudinary Uploader offers a powerful alternative. With just one command, you can upload hundreds of images and videos into organized Cloudinary folders β€” complete with progress tracking and error handling.

Give it a try and streamline your media management today.


πŸ”— GitHub Repository: manthanank/cloudinary-uploader
πŸ§‘β€πŸ’» Author: Manthan Ankolekar


Top comments (0)