2017-06-13 141 views
-1

我正在研究需要脫機工作的離子項目。我的問題是,如何在sqlite數據庫中離線保存上傳的圖像,以及何時跟蹤任何無線連接,與網上同步。使用sqlite離子應用程序離線保存圖像

圖像上傳在線工作正常,使用科爾多瓦相機插件和文件傳輸插件。

+0

爲什麼不ü儘量保留客棧地方,並將它推當u得到哪些錯誤與問題的連接 –

+0

給它打負?我要求將圖像永久保存在sqlite數據庫中。 –

回答

1

您可以使用cordova文件插件的copyfile方法在本地存儲圖像,然後將其鏈接保存在數據庫中以備後用。當檢測到wifi時,只需使用該鏈接將文件上傳到服務器就可以使用相同的cordovafile插件。

$cordovaCamera.getPicture(options).then(function(sourcePath) { //for capturing image 

console.log(sourcePath); 
var sourceDirectory = sourcePath.substring(0, sourcePath.lastIndexOf('/') + 1); //image file with path url 
var sourceFileName = sourcePath.substring(sourcePath.lastIndexOf('/') + 1, sourcePath.length); //image name 
console.log("Copying from : " + sourceDirectory + sourceFileName); 
console.log("Copying to : " + cordova.file.dataDirectory + sourceFileName); 

//used to store file locally 
$cordovaFile.copyFile(sourceDirectory, sourceFileName, 
cordova.file.dataDirectory, sourceFileName).then(function(success) { 
    $scope.fileName = cordova.file.dataDirectory + sourceFileName; 
    console.log($scope.fileName, success); 
    $scope.propic = $scope.fileName; 

}, function(error) { 
    console.log(error); 
}); 
}, function(err) { 
    console.log(err); 
});