如何在上传图像时将表单输入作为元数据插入到FS.Collection中?

时间:2015-03-25 09:12:32

标签: javascript node.js collections meteor

我将图像插入到FS.Collection中,基于Ethaan的这个例子 - https://github.com/Ethaan/simple-uploadFS/。但我需要上传2个输入值和2个与图像连接的选择值。我认为将它们作为元数据插入是最好的解决方案,因为它适用于存储Meteor.userId()。我如何存储这些值?



Template.profile.events({
  'change #exampleInput':function(){
    var file = $('#exampleInput').get(0).files[0] //Some jQuery to get the value.
        fsFile = new FS.File(file);

        fsFile.metadata = {
          coolText:"coolText",
          ownerId:Meteor.userId(),
          title:$(event.target).find('[name=bookTitle]').val(),
          format:$(event.target).find('[name=bookFormat]').val(),
          category:$(event.target).find('[name=bookCategory]').val(),
          description:$(event.target).find('[name=bookDescription]').val()
         } //FS.File support metadata.
    BookImage.insert(fsFile,function(err,result){
        if(!err){
           console.log(result) //you should get an id here since the full object take more less 10 sec to upload
         }
     })
  }
});






<template name="profile">
<form class="form">
	
  <ul class="list-group-item" id="submit">
    <li><p>Book Title :</p><input autofocus="autofocus" type="text" id="bookTitle" name="bookTitle"></li>
    <div class="image">
    <li><p>Book Cover :</p><input type="file" id="exampleInput"> </li>
      </div>
    <li><p>Book Format :</p><select id="bookFormat" name="bookFormat">
      <option value="ebook">Ebook</option>
      <option value="audiobook">AudioBook</option>
      <option value="pdf">PDF</option>
    </select></li>
    <li><p>Book Category :</p><select id="bookCategory" name="bookCategory">
      <option value="tech">Tech</option>
      <option value="business">Business</option>
      <option value="design">Design</option>
      <option value="scifi">Sci-fi</option>
      <option value="biography">Biography</option>
      <option value="science">Science</option>
    </select></li>
    <li><p>Book Description :</p><textarea id="bookDescription" name="bookDescription"></textarea></li>
  </ul>

</form>
</template>
&#13;
&#13;
&#13;

0 个答案:

没有答案