Created
December 24, 2018 02:14
-
-
Save glendaviesnz/9be2f12af7115bb0f5aa85efbf9f2a00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function httpUpload(file) { | |
return Observable.create((observer) => { | |
var config = { | |
onUploadProgress: (progressEvent) => { | |
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total); | |
observer.next({ progress: percentCompleted }); | |
} | |
}; | |
axios.post(`${appConfig.apiUrl}/upload`, file, config) | |
.then((response) => { | |
observer.next({ status: response.status }); | |
observer.complete(); | |
}) | |
.catch((error) => { | |
observer.error(error); | |
}); | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment