Cordova Meteor应用程序不允许加载本地资源

时间:2015-02-13 15:39:01

标签: javascript cordova mobile meteor html5-filesystem

我正在研究需要离线工作的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;
        }
    }
});

1 个答案:

答案 0 :(得分:0)

尝试添加,

App.accessRule("http://meteor.local/*");

到应用根目录中的mobile-config.js

参考:http://docs.meteor.com/#/full/App-accessRule