Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1B1EA10BE5 for ; Sat, 16 Nov 2013 18:12:05 +0000 (UTC) Received: (qmail 37654 invoked by uid 500); 16 Nov 2013 18:12:04 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 37622 invoked by uid 500); 16 Nov 2013 18:12:04 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 37613 invoked by uid 99); 16 Nov 2013 18:12:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Nov 2013 18:12:04 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of north.n@gmail.com designates 209.85.220.42 as permitted sender) Received: from [209.85.220.42] (HELO mail-pa0-f42.google.com) (209.85.220.42) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Nov 2013 18:11:57 +0000 Received: by mail-pa0-f42.google.com with SMTP id kx10so4230062pab.29 for ; Sat, 16 Nov 2013 10:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=cSoaJbRBUFuBfSL5sT/D+9e5Sjv3GUfm+uklHjWZLWY=; b=Mz9/cNoL+zhcbMnD3u486apXv5m2fLyqq8UsWtcbCuz/4RHIGjtaMPhJRepbDtvJ1q akf1HLdb54n1uwElDVyO95iaDmeSR3mb/2KA4iZe5OCanm5KRrDIOgObrDoemZFK9lKk fM+6nw7AKGl8uZPEet2g3NUfmF2jPy8loqzmie351nqGjPDk9G9V7jPxQrtvNB+esp7s 8PHKvLm88rsEf6NdXf1nqKYPTtaxpTAjwKmcJb/hYxiRvKL2nHEueC8BqdLklrA8sSXs 11fFjv3rk7ddWD82x8rfZmazoHnTEkTeZp1/WYPwmda4ciSc+/xryQ2NIiDYL4RjGKtP qjWg== MIME-Version: 1.0 X-Received: by 10.66.184.168 with SMTP id ev8mr13024798pac.152.1384625496152; Sat, 16 Nov 2013 10:11:36 -0800 (PST) Received: by 10.68.213.234 with HTTP; Sat, 16 Nov 2013 10:11:36 -0800 (PST) Date: Sat, 16 Nov 2013 18:11:36 +0000 Message-ID: Subject: Why does CouchDb need attachment length? From: Nick North To: dev@couchdb.apache.org Content-Type: multipart/alternative; boundary=047d7bdc78ead8633c04eb4f3ecc X-Virus-Checked: Checked by ClamAV on apache.org --047d7bdc78ead8633c04eb4f3ecc Content-Type: text/plain; charset=ISO-8859-1 I'm working with CouchDb documents with multiple attachments, submitted using MIME multipart/related requests. In this case the document JSON has to have an "_attachments" property specifying each attachment's name, content type and length as described here. The document and attachments are MIME-encoded and submitted in a single request. Although this works, programming it is awkward as each attachment's length must be known in advance in order to populate the _attachments property. Attachments are often in the form of streams, and finding the length means having to read through the whole stream. Then you have to spool through the stream again when submitting the HTTP request. (In some languages I suspect the only way to do this is to buffer the entire stream contents in memory.) If the length did not have to be put into the initial JSON object, then the stream could just be passed straight through to the HTTP request with no need for reading twice or buffering in memory. So my question is: why does CouchDb require the length to be supplied? It's definitely necessary as I've tried giving the wrong length, or no length at all, and that causes the request to fail. But a quick look at the Erlang source suggests that the length is not used when parsing the request, and presumably that parsing process could calculate each attachment's length for use later on if it's needed. If, in principle, the length could be dropped when submitting requests, then I'd be interested in trying to modify the code to make that possible. But, if there is a good reason why it has to be supplied, then I don't want to waste time working out what's going on in the Erlang. So any advice on why attachments were designed as they are would be very welcome. Many thanks, Nick --047d7bdc78ead8633c04eb4f3ecc--