Open rolinger opened 3 years ago
I then outputted the file systems the plugin is grabbing and got this, Can anyone tell me whats happening here?
document.addEventListener('DOWNLOADER_gotFileSystem', function() {
console.log(event.data) ;
}) ;
document.addEventListener('DOWNLOADER_gotFolder', function() {
console.log(event.data) ;
}) ;
2020-12-09 10:10:00.585683-0500 AttendaGo[6196:7131475] [{"isFile":false,"isDirectory":true,"name":"","fullPath":"/","filesystem":"<FileSystem: persistent>","nativeURL":"file:///var/mobile/Containers/Data/Application/7C66DE16-73C0-4F10-99B8-8D42B8A01920/Documents/"}]
2020-12-09 10:10:00.592567-0500 AttendaGo[6196:7131475] [{"isFile":false,"isDirectory":true,"name":"download","fullPath":"/download/","filesystem":"<FileSystem: persistent>","nativeURL":"file:///var/mobile/Containers/Data/Application/7C66DE16-73C0-4F10-99B8-8D42B8A01920/Documents/download/"}]
2020-12-09 10:10:00.594968-0500 AttendaGo[6196:7131475] -[CDVFileTransfer download:] [Line 423] File Transfer downloading file...
2020-12-09 10:10:01.026073-0500 AttendaGo[6196:7131762] -[CDVFileTransferDelegate connection:didReceiveResponse:] [Line 771] Streaming to file /var/mobile/Containers/Data/Application/7C66DE16-73C0-4F10-99B8-8D42B8A01920/Documents/download//Word1.DOC
2020-12-09 10:10:01.039425-0500 AttendaGo[6196:7131832] File Transfer Finished with response code 200
2020-12-09 10:10:01.040594-0500 AttendaGo[6196:7131832] -[CDVFileTransferDelegate connectionDidFinishLoading:] [Line 637] File Transfer Download success
This issue is only happening on iOS....the double //
at the end of the write-to-path is def causing the issues, but trying to figure out where its coming from has been challenging:
I found these two areas that deal with removing/adding /
from/to the path:
downloader.js, line 136 removes extra /
s from the original filenames, not certain its working though...I think the leading /
before the actual filename is not being removed, so later when a /
is added back to the write-to-path its causing the double //
var fileObject = {
url: url,
name: name || url.replace(/^.*\//, ""),
md5: md5
};
and line 203 adds a /
back to the path before the file name:
/**
* @param {FileObject} fileObject
*/
transferFile: function(fileObject) {
//console.log("tranfserFile");
var filePath = Downloader.localFolder.toURL() + "/" + fileObject.name;
Downloader.transfer = new FileTransfer();
Downloader.transfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
var percentage = Math.floor(progressEvent.loaded / progressEvent.total * 100);
document.dispatchEvent(createEvent("DOWNLOADER_downloadProgress", [percentage, fileObject.name]));
}
};
Downloader.transfer.download(fileObject.url, filePath, function(entry) {
// console.log("transferFile, succcess file name: " + Downloader.fileObjectInProgress.name);
document.dispatchEvent(createEvent("DOWNLOADER_downloadSuccess", [entry]));
}, function(error) {
// console.log("transferFile, error file name: " + Downloader.fileObjectInProgress.name);
document.dispatchEvent(createEvent("DOWNLOADER_downloadError", [error]));
});
},
Think I will need to parse the filePath and remove double //
with a regex. Be easier than trying to account for iOS
vs Android
fileSystem structures.
I fixed that issue by adding:
filePath = filePath.replace(/\/\//g, "/") ;
However, now I am getting another error:
Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'result.lengthComputable')
Its coming from line 202 in FileTransfer.js of the cordova-plugin-file-transfer
plugin.
Using cordova, I have this all working on Android...and mostly on iOS too. However, after the download on iOS I can't find the file anywhere.
Here is my download function:
in xCode, I get the following write line, its like an extra
/
is being added to the write path:Specifically, this is the path, at the end, before the file name is the double
//
- /var/mobile/Containers/Data/Application/EADA1122-72EB-4A9A-8BF9-75D3F57E0147/Documents/download//Word1.DOCOn Android, I can find the file in the
download
folder, but on iOS there is no such folder, and even if there was, the double // before the file name would still mess things up.How can I get this file to save to the root
Documents
orDownloads
folder...the public one....on iOS?