Uploading Files to a Backend API
Use FormData and fetch to POST files and track upload progress.
Welcome
In this lesson you will use the FormData API and fetch to POST files to a backend, track upload progress with XMLHttpRequest, and display upload state in React.
FormData API
FormData is a browser API that builds multipart/form-data request bodies — the format servers expect for file uploads. Append the file and any metadata fields to a FormData object.
const formData = new FormData();
formData.append('file', selectedFile);
formData.append('description', 'Profile photo');All lessons in this course
- Uncontrolled Inputs with useRef
- File Input & Reading File Data
- Drag & Drop File Upload UI
- Uploading Files to a Backend API