The Delete media API

In the backend, we will add a DELETE route that allows an authorized user to delete their uploaded media records.

mern-mediastream/server/routes/media.routes.js:

router.route('/api/media/:mediaId')        .delete(authCtrl.requireSignin,                     mediaCtrl.isPoster,                         mediaCtrl.remove)

When the server receives a DELETE request at '/api/media/:mediaId', it will first make sure the signed-in user is the original poster of the media that needs to be deleted. Then the remove controller method will delete the specified media details from the database.

mern-mediastream/server/controllers/media.controller.js:

const remove = (req, res, next) => {  let media = req.media    media.remove((err, deletedMedia) => {      if (err) { return res.status(400).json({ ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.