May 2018
Intermediate to advanced
470 pages
13h 54m
English
We will set up a route to the photo stored in the database for each user, and also add another route that will fetch a default photo if the given user has not uploaded a profile photo.
mern-social/server/routes/user.routes.js:
router.route('/api/users/photo/:userId') .get(userCtrl.photo, userCtrl.defaultPhoto)router.route('/api/users/defaultphoto') .get(userCtrl.defaultPhoto)
We will look for the photo in the photo controller method and if found, send it in the response to the request at the photo route, otherwise we call next() to return the default photo.
mern-social/server/controllers/user.controller.js:
const photo = (req, res, next) => { if(req.profile.photo.data){ res.set("Content-Type", req.profile.photo.contentType) ...Read now
Unlock full access