问题
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