如何使用cfs在Meteor中保存到/公开:文件系统和collectionfs?

如何使用cfs在Meteor中保存到/公开:文件系统和collectionfs?,meteor,collectionfs,Meteor,Collectionfs,/lib/collections/images.js var imageStore = new FS.Store.FileSystem("images", { // what should the path be if I want to save to /public/assets? // this does not work path: "/assets/images/", maxTries: 1 }); Images = new FS.Collection("image

/lib/collections/images.js

var imageStore = new FS.Store.FileSystem("images", {
  // what should the path be if I want to save to /public/assets?
  // this does not work
  path: "/assets/images/", 
  maxTries: 1
});

Images = new FS.Collection("images", {
  stores: [imageStore]
});

Images.deny({
  insert: function() {
    return false;
  },
  update: function() {
    return false;
  },
  remove: function() {
    return false;
  },
  download: function() {
    return false;
  }
});

Images.allow({
  insert: function() {
    return true;
  },
  update: function() {
    return true;
  },
  remove: function() {
    return true;
  },
  download: function() {
    return true;
  }
});
Template.test.events({

  'change .myFileInput': function(event, template) {
    FS.Utility.eachFile(event, function(file) {
      Images.insert(file, function (err, fileObj) {
        if (err){
           // handle error
        } else {
           // handle success
        }
      });
    });
  },

});
/client/test.html

<template name="test">

    <input type="file" name="myFileInput" class="myFileInput">

</template>
对于路径,如果我使用:

path: "/public/assets/images",
错误:EACCES,权限被拒绝'/public'

path: "/assets/images",
错误:EACCES,权限被拒绝'/assets'

path: "~/assets/images",

这是可行的,但它会将映像保存到我的Linux机器上的
/home/assets/images
。路径与Meteor项目根本不相关。

/
不代表站点的根目录
/
表示系统的根目录。meteor应用程序以您的用户身份运行

您需要做的是使用相对路径。collectionFS
fs.write
操作可能不是从应用程序根目录中完成的。因此,您也可以使用
path:process.env.PWD+'/public/assets/images'

您可以使用

 var homeDir = process.env.HOMEPATH;
 tmpDir: homeDir + '/uploads/tmp'

我已使用meteor root软件包解决了此问题:

所以现在它将文件存储在app/public/uploads中/


希望这有帮助

谢谢。顺便说一句,
process.env.PWD
是什么意思?它看起来像是
PWD
代表
password
,但在这个上下文中没有任何意义。这是一种unix思维。它代表“打印工作目录”。如果用户将图像存储在公共目录中,则服务器控制台上会显示消息“=>Client modified--refreshing”,并刷新网页@fuzzybabybunny你遇到过同样的事情吗?有趣的是,在Android Cordova环境中,
process.env.PWD
生成路径
。meteor/local/Cordova build
,该路径与meteor应用程序的路径相关。因此,您的解决方案将无法在移动环境中工作(我想iOS也是如此)。我解决了这个问题,在我的应用程序结构的根目录下添加了一行
settings.json
。行是:
“root”:“my/local/absolute/path/meteor\u project\u name”
(您可以通过在Unix/Linux/OS X中的终端内运行
pwd-P
来读取它)它不是自动的,因此,我必须为prod配置它。我还没有尝试过Andrew Tolochka的解决方案。请添加一些关于您的解决方案的注释,说明为什么以及如何解决问题您必须首先设置环境变量
HOMEPATH
,这不是标准。你不是在说你是怎么做到的。Meteor建议使用
process.env.VARIABLE\u NAME=some\u VARIABLE\u value
lib/server
中的文件或
server/lib
中的文件设置环境变量。这只是一个额外的间接过程,不能解决问题。它工作得非常好。这应该是公认的答案。
Files = new FS.Collection("files", {
    stores: [new FS.Store.FileSystem("images", {path: Meteor.absolutePath + '/public/uploads'})]
});