androidangularionic-frameworkionic5socialshare

How to share a local file using SocialShare Plugin in Ionic5 project?


I am pretty new to Javascript and Ionic framework . I want to share a local file which has the path "/assets/input.json" using SocialShare Plugin and I want to share this local file which is of .json extension into a .txt file through the app.

Can anyone please help with how should I use this plugin to access my local file and how can I convert it into a text file for sharing it.


Solution

  • Try this Reference : https://www.npmjs.com/package/cordova-plugin-x-socialsharing

    var options = {
      message: 'share this', // not supported on some apps (Facebook, Instagram)
      subject: 'the subject', // fi. for email
      files: ['', ''], // an array of filenames either locally or remotely
      url: 'https://www.website.com/foo/#bar?a=b',
      chooserTitle: 'Pick an app', // Android only, you can override the default share sheet title
      appPackageName: 'com.apple.social.facebook', // Android only, you can provide id of the App you want to share with
      iPadCoordinates: '0,0,0,0' //IOS only iPadCoordinates for where the popover should be point.  Format with x,y,width,height
    };
    

    For file conversion from .json to .txt you can read & write file using js (https://www.websparrow.org/web/how-to-create-and-save-text-file-in-javascript) and ionic libraries https://ionicframework.com/docs/native/file