How To Upload Multiple files to Cloudinary in Nodejs using Promise.all

Cloudinary

It has remained something confusing while perusing cloudinary documentation on how exactly do you upload multiple images, for most developers what they tend to do is to call the single file upload method on the SDK in a loop, while this seems to work at times it gets buggy when one of the files has to take more time than the other because of the size. To follow along the tutorial you can download the starter boilerplate nodejs with express code from [Github ](https://github.com/wonderfulolanrewaju/multi-file-uploader).

We need to add multer configuration to our server.js file, then use this to create an. upload middleware function.

First Acts

Second Acts

Add the following object to your package.json

What this does is allow us to make our server restart on save and run our js file with Esm module so we can use import syntax

Third Acts: Change the top part of server.js

Acts Four
What we do next is used the upload middleware function created from multer, this middleware’s array method : “upload.array(nameOfFilesFields, maxCount)” takes the name we want to call the file field and the maximum number of images it should allow for upload.

> You can run yarn dev. your app should be running on localhost:9000

You can make a request to http://localhost9000/images with the form-data request body type using pictures as field name a sample screenshot is shown below

You can also view the sample response json on a Public directory

The completed version of the code is available on Completed branch on Github and live version available on Heroku.

Fullstack Developer (MERN, Typescript, Python and SQL)