[英]Cordova Meteor app not allowed to load local resource
我正在开发需要离线工作的Meteor Cordova应用程序。
我正在使用ground:db脱机缓存我的数据,除了图像之外,该方法工作正常。 我有一个使用collectionFS的图像集合。 由于这些图像需要在脱机时可用,因此我开发了某种本地同步来观察图像收集,并在添加或更改了某些图像后,使用cordova文件系统和文件传输将图像下载到本地存储中。 我在客户端集合中跟踪下载的图像。
在模板中使用图像时,我检查图像是否在本地存在。 如果是这样,我将本地文件路径传递给模板,否则传递URL。
(android:http://meteor.local/:0) Not allowed to load local resource: file:///storage/emulated/0/brachot/AbsoluteBlackGepolijst.jpg
Meteor移动应用程序访问本地文件系统是否存在某种问题?
这是我的一些相关代码:
Images.find().observe({
added: function(doc){
console.log('added: ' + doc.original.name);
var localImage = LocalImages.findOne(doc._id);
if (!localImage && window.fileSystem && window.fileSystem.root){
// create filepath for new file
var dir = window.fileSystem.root.getDirectory("brachot", {create: true, exclusive: false}, function(dirEntry){
var file = dirEntry.getFile(doc.original.name, {create: true, exclusive: false}, function(fileEntry){
var filePath = fileEntry.toURL();
// download the file to the filepath
var fileTransfer = new FileTransfer();
console.log('starting file download: ' + doc.url() + ' to ' + filePath);
fileTransfer.download(
doc.url(),
filePath,
function(){
// download image and save locally
LocalImages.insert({
_id: doc._id,
name: doc.original.name,
url: filePath
});
console.log('save');
},
function(error){
console.log('failed to save image: ' + filePath + ' (error: ' + error.http_status + ')');
}
);
});
}, function(error){
console.log(JSON.stringify(error));
});
Template.materials.helpers({
imageUrl: function(){
var image = LocalImages.findOne({name: this.image});
if (!image) {
image = Images.findOne({'original.name': this.image});
return image.url();
}
else {
return image.url;
}
}
});
尝试添加,
App.accessRule("http://meteor.local/*");
到应用程序根目录中的mobile-config.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.