Logo

dev-resources.site

for different kinds of informations.

The easiest way of uploading image and audio files together using Multer, Cloudinary, and Node.js.

Published at
6/22/2023
Categories
webdev
node
multer
cloudinary
Author
itsfarhankhan28
Categories
4 categories in total
webdev
open
node
open
multer
open
cloudinary
open
Author
15 person written this
itsfarhankhan28
open
The easiest way of uploading image and audio files together using Multer, Cloudinary, and Node.js.

The project listπŸ“ƒ of a backend web developer always includes projects on REST API and other websites projects such as E-commerce with fully functional backends. One main functionality of these kinds of projects is file uploading such as image, audio, video, etc.

When working with MERN stack one of the most common and popular way of uploading a file is using-

The most probable solutions for uploading a file found on the internet are-

You have to search a lot to find the perfect solution for uploading the image and audio file together using multer, cloudinary and node.js.

I hope that this blog of mine is going to help most of the backend web developers for easily uploading the image and the audio file together using multer, cloudinary and node.js.

Prerequisites

  • Node.js and Express.js
  • Multer
  • Cloudinary

Let us start with uploading the image and audio file

First of all let's setup the express app. Following are the steps to create an express app.

  • Create a folder server which contains a server.js file which will be the root file.

  • Run the following command to initiate the node modules.



npm init
npm i
npm i node-modules


Enter fullscreen mode Exit fullscreen mode
  • Install express using following command.


npm i express


Enter fullscreen mode Exit fullscreen mode
  • Setup the express app in the following way.

Image description

Once the initial setup is done we will move further with the:-

  • Addition of middlewares such as app.use(express.json()) and app.use(express.urlencoded({extended: true})); and connection of mongodb using mongoose in server.js file.

Image description

  • In the following way the routes setup is done.

Image description

Now lets setup the Multer file which is in the middlware folder.
For uploading the image and audio file together we are going to use a third party dependency namely multer-storage-cloudinary

In the following way the multer setup is done using the third party dependency.

Image description

Now we will use the upload.fields as a middleware.

Image description

We are also going to setup the cloudinary in the cloudinaryconfig.js file so as to use it as a middleware in the server.js file.

Image description

Image description

Once the setup of Multer, Cloudinary is done we will take a quick peek of the controller.js.

Image description

In the uploadcontrol.js file:-

  • First of all we have created an async function namely Create.
  • Then we have stored the path of both the image and the audio file in the constants imageurl and audiourl.
  • In the last step we have stored the value of both imageurl and audiourl in the Uploads db.

Once the entire setup is done we will check the upload request on Postman

Image description

Hurrey!πŸ₯³πŸ₯³ we are successfully receiving the url of both the files.
And also getting the url stored in mongodb.

Image description

So I hope that this tutorial is going to help all the backend web developers out there in uploading the image and audio file together using Multer, Cloudinary and Node.js

multer Article's
30 articles in total
Favicon
Mastering Image Uploads in Node.js: A Beginner-to-Advanced Guide with Multer and Cloudinary
Favicon
Mastering Image Uploads with Multer, Firebase, and Express in Node.js
Favicon
File-Type Validation in Multer is NOT SAFEπŸ™ƒ
Favicon
Simplify File Uploads with @fluidjs/multer-cloudinary in Express.js
Favicon
How to Upload an Excel File in Node.js Using Express and Multer
Favicon
How to Upload a File in nodejs: A step by step guide
Favicon
Understanding the File Upload Middleware with Cloudinary in Node.js
Favicon
OPTICAL CHARACTER RECOGNITION USING NODE JS AND TESSERACT OCR ENGINE
Favicon
Upload image files with Multer
Favicon
Upload File to S3 Using NestJS Application
Favicon
The easiest way of uploading image and audio files together using Multer, Cloudinary, and Node.js.
Favicon
Uploading and Managing Images with Node.js, Multer, and Cloudinary: A Comprehensive Guide
Favicon
Unexpected end of form when sending form data with Postman- Multer
Favicon
How do i use multer's upload.array(fieldname[, maxCount]) for a nested object inside a mongoose subdocument
Favicon
The file melting Multer with NodeJS and Express
Favicon
Error: Multipart: Boundary not found
Favicon
How to validate uploaded files in Node JS
Favicon
Single and multiple images upload and remove from Cloudinary using Node JS, Multer, MongoDB
Favicon
How To Upload Files With Multer Node.js and Express
Favicon
Nodejs Express RestAPI – Upload/Import CSV File to MySQL – using Fast-CSV & Multer
Favicon
Nodejs Express RestAPI – Upload/Import Excel file/data to MongoDB – using Convert-Excel-to-Json + Multer
Favicon
Nodejs Express RestAPI – Upload/Import Excel File to MySQL – using Read-Excel-File & Multer
Favicon
Node JS Resize Image Upload Using Multer Sharp With Example
Favicon
Nodejs Express RestAPI – Upload/Import CSV file/data to MongoDB – using CsvToJson + Multer
Favicon
NodeJS/Express – Upload/Download MultiparFile to MySQL – Multer + Sequelize + JQuery Ajax + Bootstrap
Favicon
NodeJS/Express – RestAPI to Upload Multipart File to MySQL using Multer + Sequelize ORM
Favicon
NodeJS/Express – Upload/Download MultiparFile to MySQL – Multer + Sequelize + JQuery Ajax + Bootstrap
Favicon
Implementing Multer Storage Engine in TypeScript
Favicon
How To Upload Multiple files to Cloudinary in Nodejs using Promise.all
Favicon
Multer - Build RestAPI to upload a MultipartFile to NodeJS/Express

Featured ones: