title: Request.js Simulate a File Upload (multipart/form-data)
body: <p>I have an <code>express.js</code> post function which works fine for receiving and processing a file.</p>
  
  <p>I'm trying to write a <code>jasmine</code> unit-test which simulates the same thing using <code>fs</code> &amp; <code>request</code>.</p>
  
  <pre><code>const request = require("request")
  const fs = require("fs")
  const app = require("../app.js")
  const base_url = "http://localhost:3002/"
  
  var wordFile = fs.readFileSync(__dirname + '/test.docx', 'utf8')
  
  describe("POST a word file to /word", function() {
    it("parses the word file, and returns an array of components", function(done) {
      request({
        url: base_url + "word",
        method: "POST",
        json: true,
        headers: {
          "content-type": "multipart/form-data",
        },
        body: wordFile
      }, function (error, response, body) {
           expect(response.statusCode).toBe(200)
           done()
         }
      )
    })
  })
  </code></pre>
  
  <p>I get back a 500 error but when I use the following upload view on my app it works fine:</p>
  
  <pre><code>&lt;form action="/mediaDev/word" method="post" enctype="multipart/form-data"&gt;
      &lt;input type="file" name='doc' placeholder="Select file"/&gt;
      &lt;br/&gt;
      &lt;button&gt;Upload&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Is this problem related to the fact that I'm reading the file as utf8, or something else?</p>