title: Save an image file into a database with node/request/sequelize/mysql
body: <p>I'm trying to save a remote image file into a database, but I'm having some issues with it since I've never done it before.</p>
  
  <p>I need to download the image and pass it along (with node-request) with a few other properties to another node api that saves it into a mysql database (using sequelize). I've managed to get some data to save, but when I download it manually and try to open it, it's not really usable and no image shows up.</p>
  
  <p>I've tried a few things: getting the image with node-request, converting it to a base64 string (read about that somewhere) and passing it along in a json payload, but that didn't work. Tried sending it as a multipart, but that didn't work either. Haven't worked with streams/buffers/multipart all that much before and never in node. I've tried looking into node-request pipes, but I couldn't really figure out how possibly apply them to this context.</p>
  
  <p>Here's what I currently have (it's a part es6 class so there's no 'function' keywords; also, request is promisified):</p>
  
  <pre><code>function getImageData(imageUrl) {
      return request({
          url: imageUrl,
          encoding: null,
          json: false
      });
  }
  
  function createEntry(entry) {
      return getImageData(entry.image)
          .then((imageData) =&gt; {
              entry.image_src = imageData.toString('base64');
              var requestObject = {
                  url: 'http://localhost:3000/api/entry',
                  method: 'post',
                  json: false,
                  formData: entry
              };
              return request(requestObject);
          });
  }
  </code></pre>
  
  <p>I'm almost 100% certain the problem is in this part because the api just takes what it gets and gives it to sequelize to put into the table, but I could be wrong. Image field is set as longblob.</p>
  
  <p>I'm sure it's something simple once I figure it out, but so far I'm stumped.</p>