title: How to send an object in multipart formData using request in node.js
body: <p>I'm trying to formulate a <code>POST</code> using <a href="https://github.com/request/request#forms" rel="noreferrer">request</a>, but I keep getting an error anytime I try and add the <code>to</code> object to <code>formData</code>.</p>
  
  <pre><code>var fs      = require('fs');
  var request = require('request');
  var file    = './test/assets/test.pdf';
  
  var opts = {
    url: 'my_service',
    method: 'POST',
    auth: { user: 'username', password: 'password' },
    json: true,
    formData: {
      front: fs.createReadStream(file),
      to: {
        name: 'joe bob',
        address_1: '123 main st',
        ...
      }
    }
  };
  
  request(opts, function(err, resp, body) {
    console.log(err, body);
  });
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>/sandbox/project/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:33
    source.on('error', function() {});
           ^
  TypeError: undefined is not a function
      at Function.DelayedStream.create (/Users/me/sandbox/project/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:33:10)
      at FormData.CombinedStream.append (/Users/me/sandbox/project/node_modules/request/node_modules/combined-stream/lib/combined_stream.js:43:37)
      at FormData.append (/Users/me/sandbox/lproject/node_modules/request/node_modules/form-data/lib/form_data.js:43:3)
      at appendFormValue (/Users/me/sandbox/project/node_modules/request/request.js:466:21)
      at Request.init (/Users/me/sandbox/project/node_modules/request/request.js:477:11)
      at new Request (/Users/me/sandbox/project/node_modules/request/request.js:264:8)
      at request (/Users/me/sandbox/project/node_modules/request/index.js:50:10)
      at Object.&lt;anonymous&gt; (/Users/me/sandbox/project/test.js:30:1)
      at Module._compile (module.js:460:26)
      at Object.Module._extensions..js (module.js:478:10)
  </code></pre>
  
  <p>If I remove the <code>to</code> object, everything works. </p>
  
  <p>Why is this - what am I doing wrong?</p>