title: How to know if ImageSource is a jpg or png file
body: <p>My application allows users to upload profile picture from the app to my server. It works great for .png files but it doesn't work for .jpg files.</p>
  
  <p>What I do:</p>
  
  <ol>
  <li>use ImagePicker to allow user to select image(s).</li>
  <li>display available images to user.</li>
  <li>store selected image locally when user taps save</li>
  <li>upload image in the cloud</li>
  </ol>
  
  <p>The problem is at step 3, I don't know how to know if file should be saved as png or jpg.</p>
  
  <pre class="lang-js prettyprint-override"><code>    startSelection(context: ImagePicker) {
          context
              .authorize()
              .then(() =&gt; {
                  return context.present();
              })
              .then(selection =&gt; {
                  selection.forEach(selectedItem =&gt; {
                      ImageSource.fromAsset(selectedItem).then(imageSource =&gt; {
                          this.imageUrls.push(imageSource);
                          this.selectedUrlIndex = this.imageUrls.length - 1;
                      });
                  });
              })
              .catch(err =&gt; {
                  // ...
              });
      }
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>    onSave(): void {
          const folder = fs.knownFolders.documents();
          const path = fs.path.join(folder.path, 'avatar.png');
          const saved = this.getSelectedAvatar().saveToFile(path, 'png');
  
          this.userService
              .sendImages(path)
              .then(() =&gt; {
                  // ...
              });
      }
  </code></pre>
  
  <p>My issue is at this line <code>this.getSelectedAvatar().saveToFile(path, 'png');</code>, getSelectedAvatar returns an <a href="https://docs.nativescript.org/api-reference/classes/_image_source_.imagesource" rel="nofollow noreferrer">ImageSource</a></p>