Skip to content

Instantly share code, notes, and snippets.

@glendaviesnz
Created December 24, 2018 02:14
Show Gist options
  • Save glendaviesnz/9be2f12af7115bb0f5aa85efbf9f2a00 to your computer and use it in GitHub Desktop.
Save glendaviesnz/9be2f12af7115bb0f5aa85efbf9f2a00 to your computer and use it in GitHub Desktop.
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