1

Need little help on cordovaSocialShare plugin I'm trying to share an image via Whatsapp which was selected in my ionic app but i'm not able to share the image

<form name = myForm controller="ExampleController" ng-
submit="ShareAnywhere(myForm)">
<div class="myDivClass">
<input type="file" ng-model="share.shareImage">
<button ng-click="Submitted=true">Share</button>
</div>
<form>

and below goes my controller

app.controller('ExampleController',function($scope, $cordovaSocialSharing, $filter){
$scope.shareAnywhere=function(myForm){


    var eDate = new Date();
    var message = "Hi! this is an wahtsapp msg";
    var image = this.share.shareImage;
    var link = 'http://myAwsomeWebsite.com';
    var subject = 'My Subject';
    $cordovaSocialSharing.share(message, subject, image, link);
}
});

I'm able to share the text but it wouldn't add image with it

I might be doing it completely wrong please let me know what is the correct way to do it thanks in advance

Ravi
  • 43
  • 1
  • 7

2 Answers2

1

For capturing the image on click of button added at HTML file:

takePicture(){
    Camera.getPicture({
        destinationType: Camera.DestinationType.DATA_URL,
        targetWidth: 1000,
        targetHeight: 1000
    }).then((imageData) => {
      // imageData is a base64 encoded string
        this.base64Image = "data:image/jpeg;base64," + imageData;

    }, (err) => {
        console.log(err);
    });
  }
sharePicture(){

// Share via whatsapp

this.socialSharing.shareViaWhatsApp(this.message,this.base64Image,this.url).then(() => {
  // Success!
}).catch(() => {
  // Error!
});
}

Just declare the message, image and url as string.

anothernode
  • 5,100
  • 13
  • 43
  • 62
0

the parameter image should be a path(URL) to the Image. and not the Image data.

enRaiser
  • 2,606
  • 2
  • 21
  • 39
  • Thanks for the reply enRaiser could you please let me know how to get the URL of the file?? – Ravi Aug 01 '17 at 05:54
  • https://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav – enRaiser Aug 01 '17 at 08:18