2015-05-08 27 views
3

我試圖創建一個簡單的Web應用程序,將要求用戶填寫幾個問題,然後上傳一張照片。當按下提交按鈕時,我希望將所有這些信息存儲在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. 我只能拿到文件上傳事件'change .myFileInput'。我試圖讓它上傳'點擊輸入[type = submit]'和'提交',並且不會上傳文件。點擊提交按鈕後有沒有辦法讓它上傳文件?

  2. 如何將各種文本字段中的數據添加到圖像集合中?我可以將這些添加到Images.insert()命令嗎?

回答