Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Метод в сервисе, что тянет ебаный файл с сервера */
- /* Class ProfileInfoService */
- getAvatar () {
- return this._$http({
- method: 'GET',
- url: `${this.api}/api/profiles/avatar/${this.currentUser.ProfileId}`,
- responseType: 'arraybuffer'
- }).then(res => res.data);
- }
- /* Метод в контроллере, что конвертирует этот ебаный бинарный массив в строку base64 и кеширует аватарку. АВАТАРКУ КАРЛ */
- /* Class ProfileInfoController */
- getAvatar () {
- return this._ProfileInfoService.getAvatar()
- .then(res => {
- let img = btoa(String.fromCharCode.apply(null, new Uint8Array(res)));
- document.querySelector("#avatar").src = `data:image/jpeg;base64,${img}`;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement