Download and save file $cordovaFiletransfert


#1

Hello all,

I have a problem with the plugin $cordovaFileTransfer. I try to download a picture from my server.

$scope.download = function(file){
$ionicPlatform.ready(function() {

    var url = file.download_url; 
        /* file:///data/data/com.ionicframework.projectionic787897/files/image.png */
    var targetPath = cordova.file.dataDirectory + "/" + file.filename; 
    var trustHosts = true;
    var options = {};

    $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
      .then(function(result) {
        // Success!
        //Fixme : success but i don't find my picture on my device
        console.log("result : " + JSON.stringify(result));

      }, function(err) {
        // Error
        console.log("error : " + JSON.stringify(err));

      }, function (progress) {
        $timeout(function () {
          $scope.downloadProgress = (progress.loaded / progress.total) * 100;

        })
    });	
});	

}`

The download is successfull but I don’t find my file on my device. Can you help me please :smiley:

I’m sorry to my english.


How to save image or file from other server in ionic app?
#2

I resolve my problem. I find my file in my device with fileManager.


#3

this working will for download file in device ??

I found something like “requestFileSystem” and

var fileTransfer = new FileTransfer(); fileTransfer.download

why don’t use requestFileSystem ?


#4

I can’t download file :…My code is this : :point_down:

$scope.downloadFile = function () {
$scope.img = sessionStorage.getItem(“previewImg”);

    $ionicPlatform.ready(function () {

        var url = $scope.img;
        var filename = $scope.img.substring($scope.img.lastIndexOf('/') + 1);
        /* file:///data/data/com.ionicframework.projectionic787897/files/image.png */
        var targetPath = cordova.file.dataDirectory + "/" + filename;
        var trustHosts = true;
        var options = {};
        alert(url);
        alert(targetPath);
        $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
          .then(function (result) {
              // Success!
              //Fixme : success but i don't find my picture on my device
              console.log("result : " + JSON.stringify(result));
              $cordovaToast.show("Download completed", "short", "bottom").then(function (success) {
                  console.log("Toast was shown");
              }, function (error) {
                  console.log("Toast was not shown");
              });

          }, function (err) {
              // Error
              console.log("error : " + JSON.stringify(err));

          }, function (progress) {
              $timeout(function () {
                  $scope.downloadProgress = (progress.loaded / progress.total) * 100;

              })
          });
    });

};