Programmable Media

Upload images in Node.js (video tutorial)

Last updated: Feb-14-2025

Overview

Learn how to upload assets in Node.js using the Cloudinary Node.js SDK.

Video tutorial


Video Player is loading.
Current Time 0:00
Duration -:-
Loaded: 0%
Stream Type LIVE
Remaining Time 0:00
 
1x
  • Chapters
  • descriptions off, selected
  • captions off, selected

    This video is brought to you by Cloudinary's video player - embed your own!

    View the code
    You can find the code from this tutorial in GitHub.

    Tutorial contents

    This tutorial presents the following topics. Click a timestamp to jump to that part of the video.

    Upload one image using the Node.js SDK

    Jump to this spot in the video  0:15 Having installed and configured the Cloudinary Node.js SDK, you can upload an image using the upload method of the Upload API. For example:
    Node.js
    const image = './images/my_image.jpg';
    
    cloudinary.uploader.upload(image).then(result => {
      console.log(result);
    })

    Use the async await syntax

    Jump to this spot in the video  0:57 Alternatively, you can use the async await syntax. For example:
    Node.js
    const image = './images/my_image.jpg';
    
    (async function run() {
      const result = await cloudinary.uploader.upload(image);
      console.log(result);
    })();

    Upload multiple images

    Jump to this spot in the video  1:33 If you want to upload multiple images you can loop through an array, calling the same function. For example:
    Node.js
    const images = [
      './images/image1.jpg',
      './images/image2.jpg',
      './images/image3.jpg',
      './images/image4.jpg',
      './images/image5.jpg',
    ];
    
    (async function run() {
      for (const image of images) {
        const result = await cloudinary.uploader.upload(image);
        console.log(result.secure_url);
      }
    })();

    Upload using an image URL

    Jump to this spot in the video  2:06 So far we've been using local file paths, but you can use many different file sources for your images, for example an image URL:
    Node.js
    const url = 'https://example.com/myimage.jpg';
    
    (async function run() {
      const result = await cloudinary.uploader.upload(url);
      console.log(result);
    })();

    Keep learning

    Related topics

    If you like this, you might also like...

     

    Cloudinary Academy

     

    Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.

     

    ✔️ Feedback sent!