Skip to content

Commit 9f42f91

Browse files
committed
Bugfix - atualizacao da imagem de perfil
1 parent 89bd4d9 commit 9f42f91

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/pages/profile/profile.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
<ion-content padding>
1717
<ion-avatar>
18-
<img class="circle" [src]="cliente?.imageUrl || 'assets/imgs/avatar-blank.png'">
18+
<!-- <img class="circle" [src]="cliente?.imageUrl || 'assets/imgs/avatar-blank.png'"> -->
19+
<img class="circle" [src]="profileImage">
1920
</ion-avatar>
2021
<h2 text-center>{{cliente?.nome}}</h2>
2122
<p text-center>{{cliente?.email}}</p>

src/pages/profile/profile.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { ClienteDTO } from '../../models/cliente.dto';
55
import { ClienteService } from '../../services/domain/cliente.service';
66
import { API_CONFIG } from '../../config/api.config';
77
import { CameraOptions, Camera } from '@ionic-native/camera';
8+
import { ImageUtilService } from '../../services/image-util.service';
9+
import { DomSanitizer } from '@angular/platform-browser';
810

911
/**
1012
* Generated class for the ProfilePage page.
@@ -23,13 +25,19 @@ export class ProfilePage {
2325
cliente: ClienteDTO;
2426
picture: string;
2527
cameraOn: boolean = false;
28+
// profileImage: string;
29+
profileImage;
2630

2731
constructor(
2832
public navCtrl: NavController,
2933
public navParams: NavParams,
3034
public storage: StorageService,
3135
public clienteService: ClienteService,
32-
public camera: Camera) {
36+
public camera: Camera,
37+
public imageUtil: ImageUtilService,
38+
public sanitizer: DomSanitizer) {
39+
40+
this.profileImage = 'assets/imgs/avatar-blank.png';
3341
}
3442

3543
ionViewDidLoad() {
@@ -62,9 +70,16 @@ export class ProfilePage {
6270
.subscribe(
6371
response => {
6472
this.cliente.imageUrl = `${API_CONFIG.bucketBaseUrl}/cp${this.cliente.id}.jpg`;
73+
this.imageUtil.blobToDataURL(response)
74+
.then(
75+
dataUrl => {
76+
let imageUrlTemp : string = dataUrl as string;
77+
this.profileImage = this.sanitizer.bypassSecurityTrustUrl(imageUrlTemp);
78+
}
79+
);
6580
},
6681
error => {
67-
82+
this.profileImage = 'assets/imgs/avatar-blank.png';
6883
}
6984
);
7085
}
@@ -121,7 +136,8 @@ export class ProfilePage {
121136
.subscribe(
122137
response => {
123138
this.picture = null;
124-
this.loadData();
139+
// this.loadData();
140+
this.getImageIfExists();
125141
},
126142
error => {
127143

src/services/image-util.service.ts

+12
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@ export class ImageUtilService {
1313
}
1414
return new Blob([ab], { type: mimeString });
1515
}
16+
17+
// https://gist.github.com/frumbert/3bf7a68ffa2ba59061bdcfc016add9ee
18+
blobToDataURL(blob) {
19+
return new Promise(
20+
(fulfill, reject) => {
21+
let reader = new FileReader();
22+
reader.onerror = reject;
23+
reader.onload = (e) => fulfill(reader.result);
24+
reader.readAsDataURL(blob);
25+
}
26+
);
27+
}
1628
}

0 commit comments

Comments
 (0)