How to save photos from my app to gallery ios and android

#1

Hello im building simple app that get images from remote server and display them , im trying to save images to ios/android gallery . im using filetrasnfert to get the images and in log ( ios showing )


when i tape an image it get downloaded and saved in app data I GESS but it’s not been saved to gallery

how can i save it to device album .

heer is my code :slight_smile:

any easy or best solution please

 download(url,filename) {
        console.log("im called download");
        const fileTransfer: FileTransferObject = this.transfer.create();

        fileTransfer.download(url, this.file.dataDirectory +filename).then((entry) => {

            let filePath: string = entry.toURL();
            this.base64.encodeFile(filePath).then((base64File: string) => {
                console.log("im called encodeFile");

                var blob =base64File;
                this.savetogallry(blob);
            }, (err) => {
                console.log(err);
            });


            console.log('download complete: ' + entry.toURL());

        }, (error) => {
            // handle error
        });
    }
  base64toBlob(b64Data: string, contentType?: string, sliceSize?: number): Blob {
        contentType = contentType || '';
        sliceSize = sliceSize || 512;

        const byteCharacters: string = atob(b64Data);
        const byteArrays: Array<Uint8Array> = [];

        for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
            const slice: string = byteCharacters.slice(offset, offset + sliceSize);

            const byteNumbers: Array<number> = new Array(slice.length);
            for (let i = 0; i < slice.length; i++) {
                byteNumbers[i] = slice.charCodeAt(i);
            }

            const byteArray: Uint8Array = new Uint8Array(byteNumbers);

            byteArrays.push(byteArray);
        }

        const blob: Blob = new Blob(byteArrays, {type: contentType});
        return blob;
    }

    savetogallry(blob){

        console.log("im called to save in library");
        this.base64ToGallery.base64ToGallery(blob, { prefix: '_img', mediaScanner:true }).then(
            res => console.log('Saved image to gallery ', res),
            err => console.log('Error saving image to gallery ', err)
        );

    }