2012-08-28 23 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?

相關問題