title: jQuery Ajax PUT an attachment to CouchDB doc
body: <p>I have code that does POST attachments to Couch docs using jquery.form.js. That's all good, but I really need to allow the user to enter multiple files in the form, let's say 5 files for now, then in code iterate the five files in the form, creating one new Couch doc and attachment for each file. <em>This is veeeery difficult if not impossible using only jQuery</em>. It could be done using Couch "inline attachments" but then you would need a server-side (PHP probably) script to Base64 encode the binary image data. This really isn't an option for me because this is a Couchapp.</p>
  
  <p>So <strong>the following code doesn't work</strong>, it generates an "invocation" error in jQuery. My assumption is that you can't simply add the reference to a binary file in the data attrib...</p>
  
  <pre><code>    var url= _.couchUrl() + me.photoArgs.db +"/" + 
               couchDoc._id + "/attachment?rev=" + couchDoc._rev;
      $.ajax({
          type: "PUT",
          url: url,
          headers: { 
              "Content-Length": file.size,
              "Content-Type": file.type 
          },
          data: file,
          success: function (response) {
              console.log("Attachment was uploaded");
              me.fileCnt--;
              if (me.fileCnt == 0) console.log("Attachment(s) uploaded");
          },
          error: function (response) {
              _.flashError('Attachment ajaxSubmit failed',me,response);
          }
      });
  </code></pre>
  
  <p>The code is clipped from inside a larger function. I've logged the url and the file, they both have correct data so they're not the issue.</p>
  
  <p>Does anyone think the above <em>should</em> work? If so, what am I doing wrong?</p>
  
  <p>Thanks a lot for your advice :-)</p>