0Pricing
React Academy · Lesson

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

  1. Uncontrolled Inputs with useRef
  2. File Input & Reading File Data
  3. Drag & Drop File Upload UI
  4. Uploading Files to a Backend API
← Back to React Academy