meteor upload a file to mongodb

帅比萌擦擦* 提交于 2020-01-01 07:27:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/28687779/meteor-upload-a-file-to-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!