Closed eb1 closed 9 months ago
Oh, it's definitely due to something changing in the file plugin:
cordova-plugin-file@6.0.2
directoryEntry.toURL(): file:///data/user/0/<my app>/files/
cordova-plugin-file@8.0.0
directoryEntry.toURL(): https://localhost/__cdvfile_files__/
Not sure what the guidance is here, since the toURL() call is returning different values between versions of the file plugin. I'll try pinging the dev Slack chat.
Response from the dev team Slack chat: "historical toURL was for embedding URLS in the dom and with all the scheme stuff, file/cdvfile doesn't work since its cross-origin. That's why toURL now returns a https:// url on android. I think there is a .nativeURL property if I recall correctly that should be the file:/// path"
Just tried passing in the .nativeurl
property and the database does open correctly:
window.Application.db = window.sqlitePlugin.openDatabase({name: DB_NAME, androidDatabaseLocation: directoryEntry.nativeurl}, function(db) {...}
I'm not sure how far back the .nativeurl
property goes, but it's probably worth updating the readme.md
for this plugin to indicate that's how to open the DB in a custom location starting with v. 8.0 of the file plugin. I'll mark this as closed, in case someone runs into the same issue. Thanks @brodybits!
This is a weird one. I recently upgraded the
cordova-plugin-file
to 8.0.0 andcordova-android
to 12.0.1. Somewhere along the way I lost the ability to open my sqlite db from thecordova.file.dataDirectory
. Code:console output:
Note that setting the db location to default (
location: 'default'
) works properly. I'm guessing something changed in the way the resolveLocalFileSystemURL creates the directoryEntry?