Send Image using Social Sharing Plugin in ionic

1.2k Views Asked by At

I am generating QR, and i want to share that generated QR (via) Social Sharing Plugin. Below is my code to share the image.

share() {

let currentImage= "data:image/jpeg;base64,"+ this.createdCode;
this.socialSharing.share("QR Image to share", "QRCode", currentImage, '').then(()=>{ 
  console.log('sharing success'); 
  }).
catch(()=>{ 
  console.log('not possible to share '); 
});
}

this.createdCode is the string for generating QR. The problem is, this plugin shows action sheet with list of sharing applications. But i can't able to transfer image with list of sharing apps. But i can able to transfer text. Can anyone please let me know how to transfer image with social sharing plugin.

1

There are 1 best solutions below

0
On

Social sharing plugin accepts the image as a string, so if you're using qrcode package, you can share the qr code generated to social media using data url like this:

const options = {
  errorCorrectionLevel: 'H',
  type: 'image/jpeg',
  quality: 0.3,
  margin: 4
}

qrCode.toDataURL('sample text', options, (err, url) => {
  if (err) throw err   
  this.socialSharing.shareViaTwitter("Share via Twitter", url)
   .then(async () => {
      const alert = await this.alert.create({
        header: 'Alert',
        subHeader: 'success',
        message: 'shared successfully',
        buttons: ['OK']
      });
      await alert.present();
   }).catch(async (err) => {
      const alert = await this.alert.create({
        header: 'Alert',
        subHeader: 'error',
        message: 'Error, Did not share because: ' + err,
        buttons: ['OK']
      });
    await alert.present();
  })
})