0
我想從服務器下載數據庫文件並在apk中使用它。如何將數據庫文件從dataDirectory複製到Cordova的www文件夾?
我在'cordova.file.dataDirectory'處下載了該文件。該文件已成功下載到所需的位置,但在window.plugins.sqlDB.copy()函數中,應用程序崩潰並顯示消息。
不幸的是,應用程序已停止。在數據庫目錄中唯一的 'android_metadata' 表
我使用的代碼創建
文件名爲:
var url = encodeURI("my server path");
var store = cordova.file.dataDirectory;
var fileName = "Sample";
window.resolveLocalFileSystemURL(store + fileName, appStart, downloadAsset);
function downloadAsset() {
var fileTransfer = new FileTransfer();
fileTransfer.download(url, store+fileName,function (entry) {
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
window.plugins.sqlDB.copy("Sample", 0, copysuccess, copyerror);
}
function copysuccess() {
//open db and run your queries
//app.db = window.sqlitePlugin.openDatabase({ name: "Sample" });
}
function copyerror(e) {
//db already exists or problem in copying the db file. Check the Log.
//app.db = window.sqlitePlugin.openDatabase({ name: "Sample" });
}
},
function (err) {
alert(JSON.stringify(err));
});
}
function appStart() {
alert('file available');
}
}
請幫助。
我使用fileTransfer.download()方法解決了這個問題。在成功函數中,我使用app.db = window.sqlitePlugin.openDatabase({name:「Sample」})更改了代碼。而不是'window.plugins.sqlDB.copy(「Sample」,0,copysuccess,copyerror);' – Prajakta
謝謝@DaveAlden的回覆 – Prajakta