Optimized approach to upload images to cloudinary

Author: Pranto-PaulCreated Jun 19, 2025Updated Jun 20, 2025

While learning through your crash course, I make the user route along with the controller and other files. While testing with Postman I found that when I try to upload both avatar and coverImage it takes some time. After reviewing the code, I found that because of two different file upload using await , the uploader takes a good amount of time to upload files in cloudinary as It first upload the avatar image then upload the coverImage.

To make this process more faster I try to do that process with Promise and now the async work don't have to await for previous one to complete.

javascript
 // Upload to cloudinary
       uploadedImageList = [
            avatarLocalPath ? avatarLocalPath : null,
            coverImageLocalPath ? coverImageLocalPath : null,
        ].filter(Boolean);

        const [avatar, coverImage] = await Promise.all(
            uploadedImageList.map((item) => uploadOnCloudinary(item))
        );

Source: hiteshchoudhary/chai-backend