Update Files

Let’s find out how to allow users to update the data of the uploaded file.

The third function in the CRUD operations is the update operation, which allows the user to update the data of the uploaded file. In this lesson, we’ll enable this feature in the application by creating an update option for each file so that the user can update the name and description of any chosen file.

Update service

The third service is written in services/user.service.js file, in order to update a file uploaded by a certain user in the database. We write the update service like this:

Press + to interact
// front-end/src/services/user.service.js
// ...rest of the code
const updateFile = (file) => {
return axios.put(
`/file/${file._id}`,
{ ...file },
{
headers: { ...authHeader() },
}
);
};
const UserService = {
upload,
getFiles,
updateFile
};
export default UserService;

Update form

The update operation is represented as a form the user can fill in to change the name and description of the file. ...

Get hands-on with 1400+ tech skills courses.