[SOLVED] Downloading videos from server to device gallery

I`m trying to make downloaded videos visible in android(IOS) gallery.
But all what happens is download of that video on device in the specific folder.
How can I mage the videos visible in gallery?

Here is my code:

import {App, Platform} from 'ionic-angular';
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import {Transfer, FileOpener} from 'ionic-native';
declare var cordova:any;

@Injectable()

export class FileService {
constructor(private http: Http) {

}
downloadFile(fileName, fileUrl){
    const fileTransfer = new Transfer();
    let url = encodeURI(fileUrl + fileName);
    let targetPath = cordova.file.externalDataDirectory+ "Downloads/"  + fileName; 
    fileTransfer.download(url, targetPath, true).then((entry) => {
        console.log('download complete: ' + entry.toURL());           
    }, (error) => {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code" + error.code);
    });
}
}
1 Like

Add mediascaner for Android. It will refresh file in gallery.

const fileTransfer = new Transfer();
    let validFileName = this.validateStr(fileName);
    let url = encodeURI(fileUrlBase + fileNameType);
    let targetPath = cordova.file.externalRootDirectory+ "VideVita/"  + validFileName +".mp4"; //this.cordova.file.dataDirectory
    cordova.plugins.diagnostic.requestCameraAuthorization(function(status){
        console.log("Authorization request for camera use was " + (status == cordova.plugins.diagnostic.permissionStatus.GRANTED ? "granted" : "denied"));
        fileTransfer.download(url, targetPath, true).then((entry) => {
            console.log('download complete: ' + entry.toURL());
            env.isDownloadPopupVisible = true;
            cordova.plugins.MediaScannerPlugin.scanFile(targetPath,function () {
                console.log("WIN");
                            },error=>{
                                console.log("LOSE");
                            });


        }, (error) => {
            env.canDownloadFile = false;
            console.log("download error source " + error.source);
            console.log("download error target " + error.target);
            console.log("upload error code" + error.code);
        });
    }, function(error){
        console.error(error);
    });

how to download video with progressbar in ionic3

when i wrote cordova.plugins.MediaScannerPlugin.scanFile i have error under MediaScannerPlugin is not find ! anyidea pls