【问题标题】:meteor upload a file to mongodb流星上传文件到mongodb
【发布时间】:2015-02-24 03:43:10
【问题描述】:

我正在尝试通过我的流星收藏找到一种将 mp3 文件上传到 mongo 收藏中的方法。这有点具有挑战性,因为我最终将“C:\fakepath\audio.mp3”作为保存在集合中的内容。

非常感谢任何帮助。 谢谢。

【问题讨论】:

    标签: html mongodb meteor html5-audio


    【解决方案1】:

    您正在寻找FSCollection PackageGridFS 存储适配器。

    要开始在控制台上运行它。

    meteor add cfs:standard-packages
    
    meteor add cfs:gridfs
    

    现在使用 fsCollection,您可以像这样简单地上传文件。

    第一个

    声明集合。

    AudioCollection = new FS.Collection("AudioCollection", {
      stores: [new FS.Store.GridFS("AudioCollection")]
    });
    

    创建一个简单的Event handler

    Template.example.events({
      'click #example':function(e,t){
        //Simple Event to upload files into mongo.
      }
    })
    

    然后做一个简单的helper

    Template.example.helpers({
     showAudio:function(){
       return AudioCollection.find();
      }
    })
    

    有了这个HTML

    {{each showAudio}}
      {{#if isAudio}}
       <!-- show whatever you want here -->
      {{/if}}
    {{/each}}
    

    由于此时自述文件为空,我制作了一个示例DEMO

    【讨论】:

    • 谢谢!作品!既然你似乎知道你的东西,而且那里没有太多东西......有没有办法可以控制我的事件中的助手?
    猜你喜欢
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2021-10-24
    • 2015-10-15
    • 2017-02-26
    • 1970-01-01
    相关资源
    最近更新 更多