MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / uploadFileRequest

Function uploadFileRequest

src/controller/storage/storage.ts:528–556  ·  view source on GitHub ↗
(option: RequestOptions, storageName: string, path: string)

Source from the content-addressed store, hash-verified

526}
527
528const 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
558export {
559 reupStorage,

Callers 1

UploadFileFunction · 0.90

Calls 2

getRcloneApiHeadersFunction · 0.90
convertStoragePathFunction · 0.85

Tested by

no test coverage detected