2012-08-28 59 views
0

我有一个HTML表单,我可以用它来创建当前仅包含文本内容的文档。但是,我希望能够通过表单上传文件数据。如何将文件作为附件上载到CouchDB实例?

我该怎么做?下面是我使用至今

<form class="form-horizontal well" id="submitform" name="submitform"> 
    <label class="control-label" for="brand">Brand</label> 
      <label class="control-label" for="link">Any other thoughts?</label> 
      <div class="control-group"> 
      <div class="controls"> 
       <textarea class="input" rows="3" name="notes" id="notes"></textarea> 
      </div> 
      </div> 

      <div class="control-group"> 
      <div class="controls"> 
       <input type="submit" class="btn"/> 
      </div> 
      </div> 

      <label class="control-label" for="picture[]">Got a Picture?</label> 
      <div class="control-group"> 
      <div class="controls"> 
       <input type="file" name="_attachments" id="picture" accept="image/*" multiple/> 
      </div> 
      </div> 
      </div> 
     </fieldset> 
    </form> 

我试着使用一些AJAX上传文件的形式,但我只能上传的文件名作为附件,而不是实际的内容。

$.couch.db("couchclothes").saveDoc 
    (
    { 
     type: $('#type').val(), 
     brand: $('#brand').val(), 
     fit: $('#fit').val(), 
     color: $('#color').val(), 
     link: $('#link').val(), 
     notes: $('#notes').val() 
    }, 
    { 
     success: function(data) 
     { 
     alert("Saved data ok."); 
     var id = data.id; 
     var rev = data.rev; 

     // send a PUT request here 
     } 
    } 
); 
+0

也许看看在http://计算器。 COM /问题/ 166221 /何灿我上传 - 文件 - 异步与 - jQuery的 – Dan675

回答

1

我也会对如何使用字段和文件做一个经典的POST形式感兴趣。

但是如果它是细做的数据和文件上传在两个单独的步骤(并回答你的问题)检查这个解决方案,与XHR2浏览器的工作原理:How to upload a file (attachment) from the browser?

相关问题