Save image to phone's galerry

0

I am trying to save an image to the phone’s (android) gallery using base64ToGallery (https://ionicframework.com/docs/v3/native/base64-to-gallery/), but I am getting this error:

TypeError: Object(…) is not a function

which points to this place in the plugin’s source code:

Base64ToGallery.prototype.base64ToGallery = function (data, options) { return Object(__WEBPACK_IMPORTED_MODULE_2__ionic_native_core__["cordova"])(this, "base64ToGallery", { "successIndex": 2, "errorIndex": 3 }, arguments); };

Here is my code:

saveBase64ToGallery(url) {
        const proxyurl = "https://cors-anywhere.herokuapp.com/";
        let canvas, context, imageDataUrl, imageData;
        const img = new Image();
        img.crossOrigin = 'anonymous';
        img.onload = () => {
            canvas = document.createElement('canvas');
            canvas.width = img.width;
            canvas.height = img.height;
            
            context = canvas.getContext('2d');
            context.drawImage(img, 0, 0);

            try {
                imageDataUrl = canvas.toDataURL('image/jpeg', 1.0);
                imageData = imageDataUrl.replace(/data:image\/jpeg;base64,/, '');
                console.log('imageData: ', imageData);

                let base64option : Base64ToGalleryOptions = {
                    prefix: 'img',
                    mediaScanner: true
                };
                
                this.base64ToGallery.base64ToGallery(imageData, base64option)
                    .then(
                        res => console.log('Saved image to gallery ', res),
                        err => console.log('Error saving image to gallery ', err)
                    );
            }
            catch (e) {
                console.log(e);
            }
        };
        try {
            img.src = proxyurl + url;
        }
        catch (e) {
            console.log(e.message);
        }
    }

I don’t know where this issue is coming from, maybe I need to use another package version for base64ToGallery . Can you please advise? Thanks!