Created
March 28, 2016 19:16
-
-
Save Spittal/7b052cbbb9fea48bb86d 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
public updateAvatar(file: File): Observable<any> { | |
return Observable.create((observer) => { | |
let formData: FormData = new FormData(), | |
xhr: XMLHttpRequest = new XMLHttpRequest(); | |
formData.append('avatar', file, file.name); | |
xhr.onreadystatechange = () => { | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
observer.next(JSON.parse(xhr.response)); | |
observer.complete(); | |
} else { | |
observer.error(JSON.parse(xhr.response)); | |
observer.complete(); | |
} | |
} | |
}; | |
xhr.open('POST', ApiUrlHelper.apiV1Url + '/user/updateAvatar', true); | |
xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('id_token')); | |
xhr.send(formData); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment