I’ve made a simple profile page, which shows the user profile picture. That picture is stored in an Amazon S3 bucket. The page also contains buttons to get a new picture from camera (bind to getCameraPicture() method), and to upload the new picture to S3 (bind to uploadPicture() method). Here is the relevant code:
<ion-avatar>
<img [src]="client?.imageUrl || 'assets/imgs/avatar-blank.png'">
</ion-avatar>
(...)
<button ion-button block (click)="getCameraPicture()">Get picture from camera</button>
<button ion-button block (click)="uploadPicture()">Upload picture</button>
Here is the code for getCameraPicture() method:
getCameraPicture() {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
this.picture = 'data:image/png;base64,' + imageData;
});
}
And here is the code for uploadPicture() method (notice the location.reload() call I made, which I believe (but not sure) is a viable way to force refreshing page data with the new uploaded picture):
uploadPicture() {
this.clientService.uploadPicture(this.picture)
.subscribe(response => {
this.picture = null;
location.reload();
});
}
That clientService.uploadPicture method is a simple service method that calls an endpoint from my backend, which uploads the picture to Amazon S3.
This works fine when testing the app in browser through ionic cordova run browser: I can upload a new picture, and that picture instantly appears as the new rendered picture in my view.
However, when testing the app in my Android devide through ionic cordova run android --device, I still can upload a new picture (I check in my S3 bucket and the new picture is there), but the view doesn’t update! It take several HOURS to see the updated picture in my app view when running it on Android device.
So how can I force picture refresh in my app on device? Thanks.