【问题标题】:Upload files in dynamic subfolders in Meteor CFS filesystem在 Meteor CFS 文件系统的动态子文件夹中上传文件
【发布时间】:2016-05-15 08:01:56
【问题描述】:

我正在使用 Meteor 本地文件系统通过 FS.Store.FileSystem API 在特定文件夹中上传我的资产。但是,我想根据类型元数据将这些资产类别明智地上传到单独的文件夹中。 我不知道如何在 Meteor 中做到这一点。原始文档建议使用 fileKeyMaker 方法。谁能解释一下,如何使用它将资产存储在单独的文件夹中?

https://github.com/CollectionFS/Meteor-CollectionFS/wiki/How-to:-Customize-the-folders-on-the-filesystem

    AssetFiles = new FS.Collection("assets",{
    stores : [
            new FS.Store.FileSystem("AssetBundle",{path : '~/uploads'})
    ],
    filter : {
        maxSize: 5048576,
        allow : {
                extensions: ['pdf','FBX','cad','jpeg','gif','png','jpg']
        }
    }
 });

【问题讨论】:

  • 能否请您将我的答案标记为正确,以帮助其他人。非常感谢。

标签: javascript meteor angular-meteor collectionfs


【解决方案1】:

如果您将文件夹创建为 hack,这并不难。只需执行以下操作:

AssetFiles = new FS.Collection("assets",{
stores : [
        new FS.Store.FileSystem("AssetBundle",{path : '~/uploads',
           fileKeyMaker: function (fileObj) {
               // Lookup the copy
               var store = fileObj && fileObj._getInfo("assets");
               // If the store and key is found return the key
               if (store && store.key) return store.key;

               var filename = fileObj.name();
               if(filename.indexOf("pdf")>-1){
                   // If no store key found we resolve / generate a key
                   // this should be: "~/uploads/pdf/<filename>"
                   return "pdf/"+filename;
               }

           }
        })
],
filter : {
    maxSize: 5048576,
    allow : {
            extensions: ['pdf','FBX','cad','jpeg','gif','png','jpg']
    }
}
});

我正在尝试做类似的事情,但没有运气,但您的文件夹数量有限。希望上述方法有效。

【讨论】:

    猜你喜欢
    • 2013-11-18
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 2012-05-10
    • 1970-01-01
    相关资源
    最近更新 更多