Hi, you can use <input type="file" />
instead of image picker plugin. .
It works for both in mobile and browser. Here is small example:
html:
<ion-button (click)="uploadFile()"> Upload & Preview </ion-button>
<img [src]="imageURL ? imageURL : 'assets/dummy-profile-pic.png'" class="rounded mx-auto d-block img-thumbnail" alt="HA">
<input type="file" *ngIf="!imageURL" (change)="fileChanged($event)" accept="image/*" class="filebtn" #fileButton />
ts:
imageURL: any;
@ViewChild('fileButton', { static: false }) fileButton;
constructor() {...}
uploadFile() {
this.fileButton.nativeElement.click();
}
fileChanged(event) {
const files = event.target.files;
console.log(files);
const reader = new FileReader();
reader.onload = () => {
this.imageURL = reader.result;
};
reader.readAsDataURL(event.target.files[0]);
}