title: How to send image as a 'File' inside of http post body
body: <p>I need to send an image up to my server as a 'File' but I can't figure out how to do this. I'm using the nativescript-camera-plus and nativescript-background-http plugin to send the request. This is the code.</p>
  
  <pre><code>                          onTakePictureTap() {
      requestPermissions().then(
          () =&gt; {
              takePicture({ width: this.width, height: this.height, keepAspectRatio: this.keepAspectRatio, saveToGallery: this.saveToGallery, allowsEditing: this.allowsEditing })
                  .then((imageAsset: any) =&gt; {
                      this.cameraImage = imageAsset;
                      let that = this;
                      imageAsset.getImageAsync(function (nativeImage, ex) {
                          if (ex instanceof Error) {
                              throw ex;
                          } else if (typeof ex === "string") {
                              throw new Error(ex);
                          }
  
                          let imgPhoto = new ImageSource();
  
                          imgPhoto.fromAsset(imageAsset).then((imgSrc) =&gt; {
  </code></pre>
  
  <p>This is where I set up nativescript-background-http</p>
  
  <pre><code>                            var bghttp = require("nativescript-background-http");
                              var session = bghttp.session("image-upload");
                              let token = JSON.parse(appSettings.getString('token'));
  </code></pre>
  
  <p>This is the request</p>
  
  <pre><code>                            var request = {
                                  url: environment.apiUrl + 'users/1/photos',
                                  method: "POST",
                                  headers: {
                                      "Content-Type": "form-data/File",
                                      "Authorization": "Bearer " + token
                                  },
                                  description: "Uploading "
                              };
  </code></pre>
  
  <p>This is the task, i send the Image and the request</p>
  
  <pre><code>                            var task = session.uploadFile(imgSrc, request);
  
                              task()
  
                          },
                              err =&gt; {
                                  console.log('Error getting image source: ');
                                  console.error(err);
                                  alert('Error getting image source from asset');
                              });
                      });
                  }, (error) =&gt; {
                      console.log("Error: " + error);
                  });
          },
          () =&gt; alert('permissions rejected')
      );
  }
  </code></pre>
  
  <p>I think the problem is that it is being sent up as an ImageAsset and not a 'File' (but im not sure). I dont think I need to change the file type, I just need to let it know that it's a 'File' like i do in postman</p>
  
  <p>This is how it looks in postman (this works)</p>
  
  <p><a href="https://i.stack.imgur.com/NJzEh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NJzEh.png" alt="Image"></a></p>