title: Capturing an image with ngx-webcam and sending it to face recognition api
body: <p>I am currently trying to directly send an image via ngx-webcam without saving it to my backend server and send it to a <a href="https://rapidapi.com/lambda/api/face-recognition-and-face-detection?endpoint=53aa3243e4b07e1f4ebe9bb3" rel="nofollow noreferrer">Face Detection API</a> via my node.js. The problem is that I keep getting an error for my header in my node.js file. How can I resolve this issue?</p>
  
  <p>I noticed that the image url being passed is quite long. Could that be an issue?</p>
  
  <p><strong>Image url:</strong></p>
  
  <pre><code>"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAHgAoADASIAAhEBAxE..."
  </code></pre>
  
  <p><strong>My error is:</strong></p>
  
  <pre><code>TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Length"
      at ClientRequest.setHeader (_http_outgoing.js:473:3)
      at FormData.&lt;anonymous&gt; (C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\lib\form_data.js:321:13)
      at C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\lib\form_data.js:265:7
      at C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\node_modules\async\lib\async.js:251:17
      at done (C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\node_modules\async\lib\async.js:126:15)
      at C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\node_modules\async\lib\async.js:32:16
      at C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\node_modules\async\lib\async.js:248:21
      at C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\node_modules\async\lib\async.js:572:34
      at C:\Users\Roger\Documents\GitHub\angular-face-recognition-app\back-end\node_modules\form-data\lib\form_data.js:105:13
      at FSReqWrap.oncomplete (fs.js:153:21)
  </code></pre>
  
  <p><strong>Front end: Angular</strong></p>
  
  <p>Component file:</p>
  
  <pre><code>//captures image function
  public handleImage(webcamImage: WebcamImage): void {
      //stores it into webcamImageg variable
      this.webcamImage = webcamImage;
      //uses fda.sendImage function to send webcamImage to api via a service
      this.fda.sendImage(this.webcamImage.imageAsDataUrl).subscribe(res =&gt; {});
  }
  </code></pre>
  
  <p>Service file</p>
  
  <pre><code> sendImage(imgUrl){
          console.log(imgUrl);
          const obj = {
            url: imgUrl
          };    
  
          return this.http.post(`${this.uri}`, obj);
      }
  </code></pre>
  
  <p><strong>Backend: node.js</strong></p>
  
  <p>Route file</p>
  
  <pre><code>facedetAPIRoutes.route("/").post(function (req, res){
      let imageUrl = req.body.url;
      myFaceDetAPI.recognizeImg(imageUrl).then(function(result) { 
       // here is your response back
       res.json(result);
      });
  });
  </code></pre>
  
  <p>Function file for api call: uses a promise</p>
  
  <pre><code>  //I believe problem lies  here somewhere
      this.recognizeImg = (url)=&gt;{
          let requestString = "https://lambda-face-recognition.p.rapidapi.com/recognize";
          let req = unirest("POST", requestString);
          let imgURL = url;   
  
             let promise = new Promise(function(resolve, reject) {
             unirest.post(requestString)
             .header("X-RapidAPI-Key", API_KEY)
             .attach("files", fs.createReadStream(imgURL))
             .field("album", ALBUM_NAME)
             .field("albumkey", ALBUM_KEY)
             .end(result =&gt; {
                 console.log("successfully recognized image");
                 resolve(result.body) // giving response back
             });
          });
  
         return promise;  
      }
  </code></pre>