如何将文件存储到 MeteorApp 中? [英] How to Store Files into MeteorApp?

查看:47
本文介绍了如何将文件存储到 MeteorApp 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Meteor Apps 中存储文件?如果是,如何?

Is There a way to store file in Meteor Apps? if yes how?

另外,我如何使用meteor 将文件数据存储在用户定义的集合中?

Also how can i store file data in user defined collections using meteor?

我对此一无所知.

提前致谢.

推荐答案

将文件存储到 MeteorJs 的最佳方式是使用 FSCollection 包.

The best way to store files into MeteorJs is using the FSCollection Package.

这个问题已经有了答案这里

我做了一个演示,这里是源代码

在 Resume 中只需运行这 2 个命令

In Resume just run this 2 commands

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

声明一个简单的FScollection

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

并执行这个简单的事件处理程序.

Template.exampe.events({
  'click #addImage':function(){
    var file = $('#inputPng').get(0).files[0],
                fsFile = new FS.File(file);
    //and also store file data in user defined collections using meteor
                fsFile.metadata = {
                    ownerId:Meteor.userId(),
                    title:$(e.target).find('#submit-title').val()
                }
                Images.insert(fsFile,function(err,result){
                    if(!err){  
                       console.log(result)                  
          }
       })
    }
 })

这篇关于如何将文件存储到 MeteorApp 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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