cordova 实现网页缓存_缓存图像URL cordova文件和相机

我使用离子angularJS创建了应用程序,设备我打开相机并使用$ cordova文件捕获图像和设备文件并将其显示在HTML上 . 现在,每当我关闭应用程序并再次重新打开时,图像就会消失,我如何缓存它或将图像URL保存到本地存储(而不是图像本身) .

$scope.takePhoto = function() {

var options = {

quality: 75,

destinationType: Camera.DestinationType.FILE_URI,

sourceType: Camera.PictureSourceType.CAMERA,

allowEdit: true,

encodingType: Camera.EncodingType.JPEG,

correctOrientation: true,

targetWidth: 100,

targetHeight: 100,

popoverOptions: CameraPopoverOptions, // for IOS and IPAD

saveToPhotoAlbum: false

};

$cordovaCamera.getPicture(options).then(function(imageData) {

onImageSuccess(imageData);

function onImageSuccess(fileURI) {

createFileEntry(fileURI);

}

function createFileEntry(fileURI) {

window.resolveLocalFileSystemURL(fileURI, copyFile, fail);

}

//5

function copyFile(fileEntry) {

var name = fileEntry.fullPath.substr(fileEntry.fullPath.lastIndexOf('/') + 1);

alert(name);

alert(fileEntry.fullPath);

var newName = makeid() + name;

alert(newName);

window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(fileSystem2) {

fileEntry.copyTo(

fileSystem2,

newName,

onCopySuccess,

fail

);

},

fail);

}

//6

function onCopySuccess(entry) {

$scope.$apply(function() {

alert(entry.nativeURL);

// Display your captured image in the tag**

$scope.urlImg = entry.nativeURL;

});

}

function fail(error) {

console.log("fail: " + error.code);

}

function makeid() {

var text = "";

var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for (var i = 0; i < 5; i++) {

text += possible.charAt(Math.floor(Math.random() * possible.length));

}

return text;

}

}, function(err) {

console.log(err);

});

}

$scope.urlForImage = function(imageName) {

var name = imageName.substr(imageName.lastIndexOf('/') + 1);

var trueOrigin = cordova.file.dataDirectory + name;

return trueOrigin;

}

HTML

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值