[英]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.