Minor changes
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
export function fetchWithProgress(url, options: RequestInit, onProgress: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null): Promise<string> {
|
||||
export function uploadWithProgress(url, options: RequestInit, onProgress: ((ev: ProgressEvent) => any) | null): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
|
||||
xhr.addEventListener("load", e => resolve(xhr.responseText))
|
||||
xhr.addEventListener("error", reject)
|
||||
xhr.onload = e => resolve(xhr.responseText)
|
||||
xhr.onerror = reject
|
||||
|
||||
if(onProgress && xhr.upload) {
|
||||
xhr.upload.addEventListener("progress", onProgress)
|
||||
xhr.upload.onprogress = onProgress
|
||||
xhr.upload.onerror = reject
|
||||
} else {
|
||||
console.error("Could not attach progress event listener")
|
||||
}
|
||||
|
||||
xhr.open(options.method || "GET", url, true)
|
||||
|
Reference in New Issue
Block a user