Upload image in contentful media library
<p>Can anyone guide me how to upload an image in contentful media library via angularjs or javascript?</p>

<p>I had gone through contentful documentation and i am unable to find anything.</p>

<p>I found this snippet but i don't think so it uploads in media library:</p>

<pre><code>var request = new XMLHttpRequest();

request.open('POST', 'https://api.contentful.com/spaces/5smsq22uwt4m/assets');

request.setRequestHeader('Authorization', 'Bearer b4c0n73n7fu1');
request.setRequestHeader('Content-Type', 'application/vnd.contentful.management.v1+json');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

var body = "{ \
  'fields': { \
    'title': { \
      'en-US': 'Bacon Pancakes' \
    }, \
    'file': { \
      'en-US': { \
        'contentType': 'image/jpeg', \
        'fileName': 'example.jpeg', \
        'upload': 'https://example.com/example.jpg' \
      } \
    } \
  } \
}";

request.send(body);
</code></pre>

<p>Any help is appreciated, Thanks.</p>