Fetch create API in the view

In api-media.js, we will add a corresponding method to make a POST request to the create API by passing the multipart form data from the view.

mern-mediastream/client/user/api-user.js:

const create = (params, credentials, media) => {  return fetch('/api/media/new/'+ params.userId, {    method: 'POST',    headers: {      'Accept': 'application/json',      'Authorization': 'Bearer ' + credentials.t    },    body: media  }).then((response) => {    return response.json()   }).catch((err) => {    console.log(err)   }) }

This create fetch method will be used when the user submits the new media form to upload a new video.

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.