From the course: Advanced Express

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating an image handling middleware

Creating an image handling middleware

From the course: Advanced Express

Start my 1-month free trial

Creating an image handling middleware

- [Instructor] In this video, we will instantiate the previously created class and create the middleware that utilizes it to handle our uploads. First, we need to make an instance of this class available in our routes, and they are already built in a way that they can accept arguments passed on from other parts of the application. We can start in server, app.js, and there, right after the feedback service on line 13, I now add const AvatarService equals require services/AvatarService. Then, a little bit further down, I will now add to line 19 const avatars equals new AvatarService, and we pass in the path where we want to store the images and its config data avatars. Why can we do that? Because the sample project already has this set. In the config file, there is already a path for the avatars defined, and this points to data, avatars, so all images will be stored in this directory. Next, we have to pass avatars down our routing chain, so I'm scrolling down until we have this app.use…

Contents