I'm working on Ionic 3 project and users can upload multiple images using the application. I want to open the file browser when click on a Button like bellow. This is the code sample I'm working on
home.ts
public openBrowser() {
const fileLoader = document
.getElementById('fileUploader') as HTMLElement;
fileLoader.click();
}
home.html
<ion-row>
<ion-col>
<input type="file" [hidden]="true" id="fileUploader" accept=".png, .jpg, .jpeg" (change)="onChangeFileInput($event)">
</ion-col>
</ion-row>
<button ion-button secondary (click)="openBrowser()">Open</button>
This is working on the browser as well as on IOS devices. But on android device. No any errors when debugging. Does anyone knows what is the issue here ?
The point is on the accept attribute of file input. You can try the following code.
<input type="file" name="myImage" accept="image/*" />
If you want to restrict in specific file types, try the following example.
<input type="file" name="myImage" accept="image/x-png,image/gif,image/jpeg" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.