Minor changes

This commit is contained in:
2018-04-17 14:41:31 +02:00
parent 68ac241106
commit 0856fc209a
2 changed files with 9 additions and 6 deletions

View File

@ -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)