apache / apache/cordova-plugin-file-transfer

Error in success callbackID on iOS

Open
#296 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
606
Forks
874
PR merge metrics
No merged PRs in 30d

Description

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

## Problem
```
[{"isFile":false,"isDirectory":true,"name":"","fullPath":"/","filesystem":"","nativeURL":"file:///var/mobile/Containers/Data/Application/900BE112-444C-4F33-84AF-F745E8EE0C91/Library/NoCloud/"}]
[{"isFile":false,"isDirectory":true,"name":"download","fullPath":"/download/","filesystem":"","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

- [x ] I searched for existing GitHub issues
- [ ] I updated all Cordova tooling to most recent version
- [x ] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start at www/FileTransfer.js:202, where the iOS success callback reports result.lengthComputable, and compare that callback with the File Transfer success log in the report. Reproduce the download on iOS 14.1 using the supplied code and check the callback payload and resulting file path. Done means a successful download does not throw a JavaScript error and the file is accessible.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.