meteor将文件上传到mongodb [英] meteor upload a file to mongodb

查看:264
本文介绍了meteor将文件上传到mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

解决方案

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



开始在控制台上运行。

  meteor add cfs:standard-packages 

meteor add cfs:gridfs

现在使用fsCollection可以简单地上传文件。 / p>

第一次



声明收藏。

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

创建一个简单的事件处理程序

  Template.example.events({
'click #example':function(e,t){
//将文件上传到mongo的简单事件。
}
})

并做一个简单的助手

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

使用此 HTML

  {{each showAudio}} 
{{#if isAudio}}
<! - 显示您想要的任何内容 - >
{{/ if}}
{{/ each}}

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


I am trying to find a way to upload an mp3 file into a mongo collection through my meteor collection. Its a bit challenging as I end up with "C:\fakepath\audio.mp3" as what is saved in the collection.

Any help is greatly appreciated. Thanks.

解决方案

You are looking for the FSCollection Package, and the GridFS Storage Adapter.

to get started run this on the console.

meteor add cfs:standard-packages

meteor add cfs:gridfs

now With fsCollection you can upload files simple as.

First

Declare the Collection.

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

Create a simple Event handler.

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

And do a simple helper

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

With this HTML

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

Since the README its empty at this moment i made a sample DEMO.

这篇关于meteor将文件上传到mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆