title: How to send a buffer in form-data to SignServer?
body: <p>I have a file in memory (in a buffer), it doesn't exist on the file system (so I can't just stream that).</p>
  
  <p>I'm trying to send it to <a href="https://www.signserver.org/doc/current/manual/integration.html#Web_Server_Interface" rel="noreferrer">SignServer</a> using HTTP.</p>
  
  <p>Here's how I try to do it:</p>
  
  <pre><code>var formdata = require('form-data'); var form = new formdata();
  
  form.append('workerName', 'PDFSigner');
  form.append('data', file_buffer);
  // or
  // escape(file_buffer.toString('binary'))
  // or
  // file_buffer.toString('binary') (without escaping)
  
  var request = form.submit('http://localhost:8080/signserver/process', function(err, res) {});
  </code></pre>
  
  <p>When I try appending <code>file_buffer</code> SignServer says that <code>data</code> is empty:</p>
  
  <blockquote>
    <p>Status 400 - Missing file content in upload</p>
  </blockquote>
  
  <p>When I try appending <code>escape(file_buffer.toString('binary'))</code> (as suggested in <a href="https://stackoverflow.com/questions/43911060/how-do-i-send-a-buffer-in-an-http-request">How do I send a buffer in an HTTP request?</a>) it's the same story.</p>
  
  <p>When I try appending <code>file_buffer.toString('binary')</code> node.js crashes saying:</p>
  
  <blockquote>
    <p>node: ../src/stream_base.cc:157 int node::StreamBase::Writev(const v8::FunctionCallbackInfo&amp;): Assertion `(offset) &lt;= (storage_size)' failed.</p>
    
    <p>Aborted (core dumped)</p>
  </blockquote>
  
  <p>How do I correctly send the file (buffer) through HTTP (multipart/form-data) in Node.JS?</p>