apache / cordova-plugin-file-transfer

Apache Cordova File Transfer Plugin
https://cordova.apache.org/
Apache License 2.0
595 stars 888 forks source link

Error in success callbackID on iOS #296

Open rolinger opened 3 years ago

rolinger commented 3 years ago

Bug Report

File is successfully downloading but getting an error in the success callback

Problem

[{"isFile":false,"isDirectory":true,"name":"","fullPath":"/","filesystem":"<FileSystem: library-nosync>","nativeURL":"file:///var/mobile/Containers/Data/Application/900BE112-444C-4F33-84AF-F745E8EE0C91/Library/NoCloud/"}]
[{"isFile":false,"isDirectory":true,"name":"download","fullPath":"/download/","filesystem":"<FileSystem: library-nosync>","nativeURL":"file:///var/mobile/Containers/Data/Application/900BE112-444C-4F33-84AF-F745E8EE0C91/Library/NoCloud/download/"}]
console log path test: file:/var/mobile/Containers/Data/Application/900BE112-444C-4F33-84AF-F745E8EE0C91/Library/NoCloud/download/Word1.DOC
File Transfer downloading file...
[CDVFileTransferDelegate connection:didReceiveResponse:] [Line 771] Streaming to file /var/mobile/Containers/Data/Application/900BE112-444C-4F33-84AF-F745E8EE0C91/Library/NoCloud/download/Word1.DOC
File Transfer Finished with response code 200
[CDVFileTransferDelegate connectionDidFinishLoading:] [Line 637] File Transfer Download success
Error in Success callbackId: FileTransfer1502202275 : TypeError: null is not an object (evaluating 'result.lengthComputable')
win@ionic://myApp/plugins/cordova-plugin-file-transfer/www/FileTransfer.js:202:26
callbackFromNative@ionic://attendago/cordova.js:295:63
ionic://myApp/plugins/cordova-plugin-ionic-webview/src/www/ios/ios-wkwebview-exec.js:129:35
promiseReactionJob@[native code]

What is expected to happen?

Its supposed to cleanly download the file.

What does actually happen?

The above error is thrown, the file can't be found anywhere in iOS folders and the app page breaks because the JS error was thrown.

Command or Code

Here is the code I am using to download the file. It all works just fine on Android, but not on iOS. I am using the codorva-plugin-file-downloader plugin which is a wrapper that uses this plugin. The error being thrown is from this plugin.

$scope.downloadLink = function(fileInfo) {
    if (fileInfo.cType == 2) {
       var dir = "images" ;
    } else {
      var dir = "docs" ;
    }
    var urlFile = "https://portal.attendago.com/files/C" +fileInfo.cID+ "/" +dir+ "/" + fileInfo.cfInfo ;
    var newFileName = fileInfo.cfName+ "." +fileInfo.cfExt ;
    let storage_location = '' ;

    if (ionic.Platform.isIOS()) {
       //storage_location = cordova.file.documentsDirectory ;
       storage_location = cordova.file.dataDirectory ;
    } else if (ionic.Platform.isAndroid()) {
       storage_location = 'file:///storage/emulated/0/' ;
    }
    let downloading = function(event) {
      var data = event.data ;
      if (data[0] != 100) {
        var msg = "Downloading file: " +data[0]+ "%" ;
        var color = "red" ;
      } else {
        var msg = "DOWNLOAD COMPLETE!" ;
        var color = "green" ;
      }
      $scope.startStatus(fileInfo.cfID,color,msg) ;
    }
    let downloaded = function(event) {
      setTimeout(function() {
        $scope.endStatus(fileInfo.cfID) ;
        event.target.removeEventListener(event.name,downloaded) ;
      },5000) ;
    }
    let initialized = function(event) {
      downloader.get(urlFile,null,newFileName) ;
      event.target.removeEventListener(event.name,initialized) ;
    } ;
    document.addEventListener('DOWNLOADER_initialized', initialized) ;
    document.addEventListener('DOWNLOADER_downloadProgress',downloading) ;
    document.addEventListener('DOWNLOADER_downloadSuccess', downloaded) ;
    document.addEventListener('DOWNLOADER_gotFileSystem', function() {
      console.log(event.data) ;
    }) ;
    document.addEventListener('DOWNLOADER_gotFolder', function() {
      console.log(event.data) ;
    }) ;
    downloader.init({folder: 'download', fileSystem: storage_location})
  }

Environment, Platform, Device

iPhone 7, iOS 14.1

Version information

Ionic:

   Ionic CLI         : 6.10.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework   : ionic1 1.0.0
   @ionic/v1-toolkit : 1.0.22

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : ios 5.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 32 other plugins)

Utility:

   cordova-res (update available: 0.15.2) : 0.15.1
   native-run (update available: 1.3.0)   : 1.2.2

System:

   ios-deploy : 1.10.0
   ios-sim    : 8.0.2
   NodeJS     : v10.21.0 (/usr/local/Cellar/node@10/10.21.0/bin/node)
   npm        : 6.14.4
   OS         : macOS Catalina
   Xcode      : Xcode 12.1 Build version 12A7403

Checklist