Javascript REST image upload example

I am currently using the JS SDK in my project.
When uploading files I am using the REST sdk in order to show an upload progress.
I am having difficulty when uploading images.
The files are saved on disk, but they all save with the same file size and when I try to open it the file is corrupt.
According to the docs it looks like uploading images are a bit different, but I am not familiar with the Curl example provided.
Would someone be able to assist with an example in javascript to upload images using the rest sdk?
Currently I am using the standard XMLHttpRequest for my rest calls.

Many Thanks.

I have managed to get it working.
I had to send the actual file object from the file input.
Previously I was sending to as a FormData object.