(option: RequestOptions, storageName: string, path: string)
| 526 | } |
| 527 | |
| 528 | const uploadFileRequest = (option: RequestOptions, storageName: string, path: string) => { |
| 529 | const { onProgress, onError, onSuccess, file } = option |
| 530 | |
| 531 | const formData = new FormData() |
| 532 | formData.append('file', file) |
| 533 | |
| 534 | const xhr = new XMLHttpRequest() |
| 535 | |
| 536 | xhr.upload.onprogress = ({ lengthComputable, loaded, total }) => { |
| 537 | if (lengthComputable) { |
| 538 | console.log(Math.round((loaded / total) * 100)) |
| 539 | onProgress(Math.round((loaded / total) * 100)) |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | xhr.onload = () => { |
| 544 | xhr.status === 200 ? onSuccess() : onError(xhr) |
| 545 | } |
| 546 | |
| 547 | xhr.onerror = () => onError(xhr) |
| 548 | |
| 549 | xhr.open( |
| 550 | 'POST', |
| 551 | `${rcloneInfo.endpoint.url}/operations/uploadfile?fs=${convertStoragePath(storageName, undefined, undefined, undefined, true)}&remote=${convertStoragePath(storageName, path, true, true, undefined)}`, |
| 552 | true |
| 553 | ) |
| 554 | xhr.setRequestHeader('Authorization', getRcloneApiHeaders().Authorization) |
| 555 | xhr.send(formData) |
| 556 | } |
| 557 | |
| 558 | export { |
| 559 | reupStorage, |
no test coverage detected