( method: "POST" | "PUT", url: string, file: UploadFile, options: FileSystem.FileSystemUploadOptions, onProgress?: (progress: UploadProgress) => void, )
| 324 | }; |
| 325 | |
| 326 | const uploadNativeFile = async ( |
| 327 | method: "POST" | "PUT", |
| 328 | url: string, |
| 329 | file: UploadFile, |
| 330 | options: FileSystem.FileSystemUploadOptions, |
| 331 | onProgress?: (progress: UploadProgress) => void, |
| 332 | ) => { |
| 333 | const task = FileSystem.createUploadTask( |
| 334 | url, |
| 335 | file.uri, |
| 336 | { |
| 337 | ...options, |
| 338 | httpMethod: method, |
| 339 | }, |
| 340 | (data) => { |
| 341 | onProgress?.({ |
| 342 | loaded: data.totalBytesSent, |
| 343 | total: data.totalBytesExpectedToSend, |
| 344 | }); |
| 345 | }, |
| 346 | ); |
| 347 | const response = await task.uploadAsync(); |
| 348 | if (!response || response.status < 200 || response.status >= 300) { |
| 349 | throw new MobileApiError( |
| 350 | "Upload target rejected the file", |
| 351 | response?.status ?? 0, |
| 352 | response?.body ?? null, |
| 353 | ); |
| 354 | } |
| 355 | }; |
| 356 | |
| 357 | const uploadWithXhr = ( |
| 358 | method: "POST" | "PUT", |
no test coverage detected