使用sqlite离子应用程序离线保存图像

问题描述:

我正在研究需要脱机工作的离子项目。我的问题是,如何在sqlite数据库中离线保存上传的图像,以及何时跟踪任何无线连接,与网上同步。使用sqlite离子应用程序离线保存图像

图像上传在线工作正常,使用科尔多瓦相机插件和文件传输插件。

+0

为什么不ü尽量保留客栈地方,并将它推当u得到哪些错误与问题的连接 –

+0

给它打负?我要求将图像永久保存在sqlite数据库中。 –

您可以使用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); 
});