Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Метод в сервисе, что тянет ебаный файл с сервера */
  2. /* Class ProfileInfoService */
  3. getAvatar () {
  4.     return this._$http({
  5.         method: 'GET',
  6.         url: `${this.api}/api/profiles/avatar/${this.currentUser.ProfileId}`,
  7.         responseType: 'arraybuffer'
  8.     }).then(res => res.data);
  9. }
  10.  
  11. /* Метод в контроллере, что конвертирует этот ебаный бинарный массив в строку base64 и кеширует аватарку. АВАТАРКУ КАРЛ */
  12. /* Class ProfileInfoController */
  13. getAvatar () {
  14.     return this._ProfileInfoService.getAvatar()
  15.         .then(res => {
  16.             let img = btoa(String.fromCharCode.apply(null, new Uint8Array(res)));
  17.             document.querySelector("#avatar").src = `data:image/jpeg;base64,${img}`;
  18.         });
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement