Upload file through API with Javascript

Is it possible to upload a file using rest API to store this file in SharePoint library from a normal html page , I will be need to pass the access token as well “Authorization” : “Bearer token”

Here is the code I used but it gives error :

<html>
<input type="file" name="file" id="file">
<button onclick="doupload()" name="submit">Upload File</button>


<script>
function doupload() {
let data = document.getElementById("file").files[0];
let entry = document.getElementById("file").files[0];
console.log("doupload",entry,data)
fetch("https://test.sharepoint.com/sites/BM/_api/web/GetFolderByServerRelativeurl
("/sites/BM/BM_UPLOADS/")/Files/add(url=entry,overwrite=true)"
 + encodeURIComponent(entry.name), {method:"POST",body:data});
alert("your file has been uploaded");
location.reload();
};

</script>