NodeJS and MongoDB Tutorial #4 - Uploading Files (Single & Multiple)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] how the welcome to take foreigner I am most women in this tutorial I will show how to upload files and images by nodejs and DB in the last video we have been completed a crude operation all of the links of my previous and after videos will be available in the video description we have an employee controller where the store function is working to store a new employee and it is the API to call the store function where the route is declared here okay so previously we were sending our data in JSON format but when we will upload images and files we have to send data in multi-part form data you must be familiar with this word because you sleep in HTML as ENC type multi-part form data in postman we will use this form data here we will take a new field to take the file currently in our model there is no field to upload a file so let us add it now we have to install a package called Mulder you can read the documentation from here Mulder is widely used to manage files in node.js now we will take a new middleware so that we can use it from anywhere of our project here we will also do some validation like acceptable file types max file size etc here it is the location where the file will be saved and it will rename the file with current timestamp and the extension which is always unique so we should take a new folder uploads so II to is support max 2mb file and only jpg and PNG images otherwise it will add the employee but will not upload the image and in the console it will show this message we have a small work in the controller and in the rap file we have to import the middle word and here it will upload single file but I will also show how to upload multiple files after some times okay so let us try it select file okay there is an arrow here it should be is too rich okay employee added successfully here the file has been uploaded and in the database it has been saved in the server JS file add the single line to access the files publicly my server is running on port 3000 so it is showing the image now I will show you how to upload multiple files and array of files simply change her array every is an array also change here you can now upload multiple files in the controller so it will save the file locations with comma-separated and also remove the last comma it should be okay let us check it okay all the images has been uploaded in the database it has been saved as comma separated you can use this anywhere by simply sliced by this comma thank you for watching this video in the next video I will show a complete login registration system by node.js and memory so it stay connected don't forget to subscribe my channel
Info
Channel: Tech Founder
Views: 84,812
Rating: undefined out of 5
Keywords: node js and mongodb tutorial, nodejs image upload, nodejs multiple file upload, nodejs multiple image upload, node js file upload, mongodb file upload, node js tutorial, mongodb tutorial, tutorial, nodejs, mongodb
Id: 62YETqynpcs
Channel Id: undefined
Length: 11min 18sec (678 seconds)
Published: Tue Feb 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.