DNY client (10 – Profile Photo Upload)

Client side

Add the html for an input control that accepts file images

src/user/EditProfile.js

Basically, we need to send the form data to the backend.
We need to use browser API called FormData

FormData interface provides a way to easily construct a set of key/value pairs representing form fields and their values.

We update our handleChange to reflect responding to photo file clicks.

src/user/EditProfile.js

We need to change our body so that we’re sending the formData, and not a string.
We also need to remove the Content-Type headers because its not json anymore. Its key/value formData

src/user/apiUser.js

Now, refresh the page and try sending a photo, for the PUT request, look at your FormData, you should see all the data there.

Server side

We comment out the previous updateUser function and write a new one.

controllers/user.js

Now, try to upload the photo.