Controller method to handle create request

The create controller method in the media controller will use the formidable npm module to parse the multipart request body that will contain the media details and video file uploaded by the user:

npm install formidable --save

The media fields received in the form data, and parsed with formidable, will be used to generate a new Media object and saved to the database.

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

const create = (req, res, next) => {  let form = new formidable.IncomingForm()    form.keepExtensions = true    form.parse(req, (err, fields, files) => {      if (err) {        return res.status(400).json({          error: "Video could not be uploaded"        })      }      let media = new Media(fields) media.postedBy= req.profile ...

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.