【问题标题】:Uploading image with a form in meteor on form submit在表单提交上使用流星中的表单上传图像
【发布时间】:2015-05-08 14:07:41
【问题描述】:

我正在尝试创建一个简单的网络应用程序,它会要求用户填写一些问题,然后上传照片。当按下提交按钮时,我希望所有这些信息都存储在 Meteor 集合中,但是我在使用 FS Collection 包时遇到了一些困难。

这里是相关的main.html:

    <form class="photoForm">
    Problem: <input type = "text" id = "problem" placeholder="page # problem #"><br><br>
    Your group members <input type = "text" id="group" size="50"> <br><br>
    Your questions and comments about this problem: <br><br>
    <textarea name="comments" form="photo" rows="4" cols="70" placeholder="Enter text here..."></textarea>
    <br>

    Upload a snapshot of your work here: <input type = "file" id = "myFileInput">
    <br /><br />

    <input type="submit" value="submit" />
    </form>

这是 main.js:

Template.form.events({ 
'click input[type=submit]': function(event, template) {

console.log("form submit")
event.preventDefault();

FS.Utility.eachFile(event, function(file) {


  Images.insert(file, function (err, fileObj){
    //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
  });

});
 }   
});

这是我的问题:

  1. 我只能在“更改 .myFileInput”事件中获取要上传的文件。我试图让它在“点击输入[类型=提交]”和“提交”上上传,但它没有上传文件。单击提交按钮时,有没有办法让它上传文件?

  2. 如何将各种文本字段中的数据添加到图像集合中?我可以将这些添加合并到 Images.insert() 命令中吗?

【问题讨论】:

    标签: forms meteor


    【解决方案1】:

    检查 autoform 包

    autoform package

    还有 cfs autoform 包 Cfs autoform

    这些包非常有用

    【讨论】:

    • 是的,我能够让它与 cfs:autoform 一起使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    相关资源
    最近更新 更多