skip to Main Content

I have a button to select multiple images multiple="multiple"
Selecting multiple images works everywhere, in all browsers. But it doesn’t work in Telegram Mini Apps on the phone https://core.telegram.org/bots/webapps. Selecting multiple images works in Telegram for desktop computers, but does not work in Mini Apps on the phone.

I’m talking about multiple. If you select one image at a time, it works.

I don’t know what the reason is.

html

    <input type="file" (change)="selectFiles($event)" accept="image/jpeg, image/png" ultiple="multiple">

TypeScript

    export class AddFormComponent {

        selectFiles(event?: any) {

            console.log(event.target.files.length)  // 0 or event>0

        } 

    } 

Please tell me what is the reason and how to solve it?

2

Answers


  1. I hope this helps!
    Telegram Image Picker library to select multiple images in Telegram Mini Apps:

    <telegram-image-picker (on-select)="selectFiles($event)"></telegram-image-picker>
    
    import { TelegramImagePicker } from 'telegram-image-picker';
    
    export class AddFormComponent {
    
        constructor(private telegramImagePicker: TelegramImagePicker) {}
    
        selectFiles(event: any) {
    
            console.log(event.detail.files.length); // event>0
    
        }
    
    }
    
    Login or Signup to reply.
  2. Another solution

    <input type="text" id="file-input" (change)="selectFiles($event)">
    
    import { FileAPI } from '@angular/compiler/testing';
    
    export class AddFormComponent {
    
        constructor(private fileAPI: FileAPI) {}
    
        selectFiles(event?: any) {
    
            const filePaths = event.target.value.split(',');
            const selectedFiles = [];
    
            for (let i = 0; i < filePaths.length; i++) {
                const filePath = filePaths[i];
                selectedFiles.push(this.fileAPI.readFile(filePath));
            }
    
            console.log(selectedFiles.length); // event>0
    
        }
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search