ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@capacitor/camera plugin is not accepting multiple images at a time from photo album.

LakshmiPamarth opened this issue · comments

Bug Report

@capacitor/camera plugin is not accepting multiple images at a time from photo album.IT is accepting multiple images from gallery but it is allowing the only one image at a time from photo album.Im using pickimages() only.

Im using ionic 6 and capacitor 5 in android 13 version.
Im using code like this
async pickImages() {
try {
const cameraPermissionStatus = await Camera.checkPermissions();
let images;

  switch (cameraPermissionStatus.camera) {
    case 'granted':
      this.logAnalytics.logEvent('Permissions granted to pick images from the gallery');
      images = await Camera.pickImages({});
      break;

    case 'prompt':
    case 'prompt-with-rationale':
      const permissionResult = await Camera.requestPermissions();
      if (permissionResult.camera === 'granted') {
        this.logAnalytics.logEvent(`Permissions granted to pick images from the gallery after prompt (${cameraPermissionStatus.camera})`);
        images = await Camera.pickImages({})
      } else {
        this.logAnalytics.logEvent(`Permissions denied to pick images from the gallery after prompt (${cameraPermissionStatus.camera})`);
      }
      break;

    case 'limited':
      this.logAnalytics.logEvent('Permissions limited to images from the gallery');
      break;

    case 'denied':
      this.logAnalytics.logEvent('Permissions denied to pick images from the gallery');
      break;

    default:
      this.logAnalytics.logEvent('Unknown camera permission status');
      break;
  }

  if (images) {
    this.pickedImages = images.photos;
    let totalImagesCount;
    if(this.images?.length>0){
      totalImagesCount= this.images?.length + this.pickedImages.length;
    }
    else{
      totalImagesCount=this.pickedImages?.length
    }

    if(totalImagesCount>5){
      this.displayAlertPopup=true;
      this.alertpopupMessage={
        textMsg:'You can not select more than 5 images',
        dialogType:'Alert'
      }
      return;
    }
  }
  try{
  this.pickedImages.forEach(async (image)=>{
    const fileData = await Filesystem.readFile({
      path:image.path
    })
    let base64data='data:image/jpeg;base64,'+fileData?.data
    let obj={

      filePath:
        new Date().getTime() +
        '.' +
        'jpeg',
      fileType: 'image',
      File: base64data
    }
    if(this.images==null){
      this.images=[]
    }
    this.images.push(obj)
    // prints base 64 string of the selected file
    this.uploadFilestoBlob = this.images
    if (this.images) {
      this.files = this.images;
      if (this.images.length == 1) {
        this.isShownSingleImg = true;
      }
      else {
        this.isShownSingleImg = false;

      }
      this.files = this.files.map(({ File, ...rest }) => rest);
    }
  //  localStorage.setItem('CapturedImages', JSON.stringify(this.images));
   await this.indexeddbService.addUpdateCachedAsset(JSON.stringify(this.images),`CapturedImages`)


    
  })

  
}
catch(error){
  this.logAnalytics.logException(error)
}

} catch (error) {
  console.error('Error in pickImages:', error);
  // Handle the error appropriately (e.g., log, show a message, etc.)
}

}

This issue needs more information before it can be addressed.
In particular, the reporter needs to provide a minimal sample app that demonstrates the issue.
If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks!
Ionitron 💙

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day!
Ionitron 💙

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.