Cordova 11 download fails
Opened this issue · 1 comments
At a loss now, spent last few hours trying to figure this one out, but downloads are failing Cordova11 (cordova-android@11)
I think this is happening on download.init
because its not getting to any other break points, can anyone help me decipher this
downloader.init({folder: 'MyApp', fileSystem: 'file:///storage/emulated/0/'}) ;
The problem persists even when I remove the fileSystem
option:
downloader.init({folder: 'MyApp',}) ;
Immediately errors with the following:
Event {isTrusted: false, name: 'DOWNLOADER_error', data: Array(1), type: 'DOWNLOADER_error', target: document, …}
data: [FileError]
isTrusted: false
name: "DOWNLOADER_error"
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: null
defaultPrevented: false
eventPhase: 0
path: (2) [document, Window]
returnValue: true
srcElement: document
target: document
timeStamp: 28616.399999976158
type: "DOWNLOADER_error"
[[Prototype]]: Event
}
I have tracked this down further, specifically data: [FileError]
. In that object is code:12
. Researching code 12 I find references from other very related plugins for file system issues.
markmarijnissen/cordova-file-cache#10
apache/cordova-plugin-file#408
https://stackoverflow.com/questions/53691634/cordova-file-plugin-return-an-error-with-code-12-path-exists-err-only-on-ios
All are very consistently referring to: https://developer.mozilla.org/en-US/docs/Web/API/FileError
Which is implying the file system/folder I am trying to write to does not exist or is inaccessible. But this was working on Cordova 10. I just upgraded to Cordova 11, cordova-androis@11 and during test came across this issue.
Figured it out. I was setting fileSystem=cordova.file.externalRootDirectory - which apparently is the default too
And cordova.file.externalRootDirectory
= file:///storage/emulated/0/
- which is apparently no longer an option in Android API 29 and higher. However, writing the file to the app data directory is NOT optimal, because how does the user gain access to it? Its not a standard Documents
folder they would naturally go to or know how to look for - making the file download pretty much hidden from the users.
Switching to cordova.file.externalDataDirectory
which translates to: file:///storage/emulated/0/Android/data/com.myApp/files/
But now that I am passed that issue, the next step in the downloader.init process fails at trying to initiate a new FileTransfer
which is sourced from cordova-plugin-file-transfer
. The error is 'unknown reference FileTransfer`
I have been trying to update/troubleshoot the cordova-plugin-file-transfer
but apparently many others having the same issue - it looks like there is a beta version (https://github.com/ns0m/cordova-plugin-ns0m-file-transfer
) that some are having luck with (independently) but I haven't gotten it work with file-downloader