title: Post form data using Node/Express and Request module
body: <p>I am able to download files from a remote vendor API and post these to Azure blob storage per this posting: <a href="https://stackoverflow.com/questions/32619369/download-file-via-webservice-and-push-it-to-azure-blob-storage-via-node-express">Download file via Webservice and Push it to Azure Blob Storage via Node/Express</a></p>
  
  <p>This is working as intended, but now I need to pass form data into the request I make to download the file, as my vendor API will send back different files based on my form data (ex. height and width of the image). This code is what downloads the file into my temporary storage per the URL passed into it via the Request module (<a href="https://github.com/request/request" rel="nofollow noreferrer">https://github.com/request/request</a>):</p>
  
  <pre><code>var r = request(req.body.url).pipe(fs.createWriteStream(tmpFileSavedLocation))
  </code></pre>
  
  <p>How can I pass in the form data I collect via my HTML form to my node/express call so I can post my form data and get the correct image height and width from my vendors API?</p>
  
  <p>Here is my HTML form:</p>
  
  <pre><code>&lt;form id="newForm" class="form-horizontal" data-ng-submit="createContainer()"&gt;
          &lt;div class="form-group"&gt;
              &lt;label class="col-lg-2 control-label" for="width"&gt;Width *&lt;/label&gt;
              &lt;div class="col-lg-2"&gt;
                  &lt;input class="form-control" name="width" id="width" type="number" step="0.01" max="20" data-ng-model="formInfo.width" required&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label class="col-lg-2 control-label" for="height"&gt;Height *&lt;/label&gt;
              &lt;div class="col-lg-2"&gt;
                  &lt;input class="form-control" name="height" id="height" type="number" step="0.01" max="20" data-ng-model="formInfo.height" required&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="col-lg-10 col-lg-offset-2"&gt;
              &lt;button type="submit" class="btn btn-primary"&gt;Create&lt;/button&gt;
          &lt;/div&gt;
          &lt;span&gt;{{formInfo}}&lt;/span&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Here is my Angular Controller:</p>
  
  <pre><code>$scope.createContainer = function () {
          // Create Blob Container
          $http.get('/createcontainer').success(function (data) {
          // This passes back the container name that was created via the createcontainer call                
              var containerName = data;
              var filename1 = 'myfile.png';
  
              // Unsure of how to pass the formdata in!!!!
              var formData = $scope.formInfo
  
              // Get myfilepng
              $http.post('/uploadapifiles', { containerName: containerName, filename: filename1, url: 'http://vendorapi.net/ws/getimage' }).success(function (data) {
                  console.log(data);
                 }, function (err) {
                  console.log(err);
              });
          });
      };
  </code></pre>
  
  <p>Here is the uploadapifiles call in my server.js:</p>
  
  <pre><code>app.post('/uploadapifiles', function (req, res, next) {
  
  var containerName = req.body.containerName;
  var filename = req.body.filename;
  var tmpBasePath = 'upload/'; //this folder is to save files download from vendor URL, and should be created in the root directory previously.
  var tmpFolder = tmpBasePath + containerName + '/';
  
  // Create unique temp directory to store files
  mkdirp(tmpFolder, function (err) {
      if (err) console.error(err)
      else console.log('Directory Created')
  });
  
  // This is the location of download files, e.g. 'upload/Texture_0.png'
  var tmpFileSavedLocation = tmpFolder + filename;
  
  // This syntax will download file from the URL and save in the location asyns
  var r = request(req.body.url).pipe(fs.createWriteStream(tmpFileSavedLocation))
  r.on('close', function () {
      blobSvc.createBlockBlobFromLocalFile(containerName, filename, tmpFileSavedLocation, function (error, result, response) {
          if (!error) {
              console.log("Uploaded" + result);
              res.send(containerName);
          }
          else {
              console.log(error);
          }
      });
  })
  });
  </code></pre>