From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Adding product to database, part 2

Adding product to database, part 2

Now, let's handle the file upload part using the multer. I'll install the multer package by giving the command npm install hyphen d at types slash multer. After installing the package, inside the post route handler, I'll give the use interceptors decorator and specify the file interceptor function. This function is a built-in utility that uses multer to handle file uploads. It is typically used as an interceptor to intercept the incoming HTTP requests and process the file data. And it is totally similar to the Node.js multer as it is built upon that only. The file interceptor takes two arguments. First is the name of the field. So if we look at the add product template, let me scroll down to the image field. Here we have set the name attribute to image and this same name we will pass as the first argument. The second argument is the storage option. Well, with Node.js, we used to create a constant for storage and then assign the disk storage engine. But as I mentioned that the file…

Contents