[SOLVED] Downloading videos from server to device gallery


#1

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);
    });
}
}

Downloading files in Ionic using cordova-plugin-file-transfer
#2

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);
    });

#3

how to download video with progressbar in ionic3