File Upload

React Native 7 min min read Updated: Jul 26, 2026 Intermediate
File Upload
Intermediate Topic 12 of 20

File Upload

Uploading files, such as documents or media, is a common requirement in React Native applications. This tutorial explains how to implement file uploads using FormData.

Selecting a File

Files can be selected using libraries such as react-native-document-picker or the device’s image picker for media-specific uploads.

bash npm install react-native-document-picker

Creating a FormData Object

javascript const formData = new FormData(); formData.append('file', { uri: selectedFile.uri, name: selectedFile.name, type: selectedFile.type, });

Uploading with Axios

javascript await axios.post('https://api.example.com/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' }, });

Tracking Upload Progress

Axios supports an onUploadProgress callback, allowing you to display a progress bar while a large file is being uploaded.

javascript axios.post(url, formData, { onUploadProgress: (progressEvent) => { const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total); setUploadProgress(percent); }, });

Handling Upload Errors

File uploads can fail due to network interruptions or file size limits, so proper error handling with clear user feedback is essential for a good upload experience.

Uploading Multiple Files

Multiple files can be appended to the same FormData object using an array-style field name, allowing the server to process them together in a single request.

javascript files.forEach((file) => { formData.append('files[]', { uri: file.uri, name: file.name, type: file.type }); });

Conclusion

File uploads using FormData, combined with upload progress tracking, provide a robust way to send documents and media from your React Native application to a backend server.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators