Using fetch:
1async function uploadFile(uri: string) {2 const formData = new FormData();3 formData.append("file", {4 uri,5 name: "photo.jpg",6 type: "image/jpeg",7 } as any);89 const response = await fetch("https://api.example.com/upload", {10 method: "POST",11 body: formData,12 headers: {13 "Content-Type": "multipart/form-data",14 },15 });1617 return response.json();18}
Progress tracking:
1import { upload } from "react-native-blob-util";23const result = await upload({4 url: "https://api.example.com/upload",5 method: "POST",6 path: filePath,7 onProgress: (sent, total) => {8 setProgress(sent / total);9 },10});
Tips: