Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

Form submission with the file attached

Uploading files to the server with a form requires a multipart form submission. This is in contrast to the stringified object we sent in previous implementations of fetch. We will modify the EditProfile component so that it uses the FormData API to store the form data in the format needed for encoding in the multipart/form-data type.

You can learn more about the FormData API at developer.mozilla.org/en-US/docs/Web/API/FormData.

First, we will update the input handleChange function so that we can store input values for both the text fields and the file input, as shown in the following code.

mern-social/client/user/EditProfile.js:

const handleChange = name => event => {  const value = name === 'photo'
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content