'Migrating to Edge Browser - file upload not working

We are migrating from IE 8 to Edge browser,

Below is the code working in IE 8, to load one file, but not in Edge.

if(window.ActiveXObject){
                var fso = new ActiveXObject("Scripting.FileSystemObject");
                var filepath = document.getElementById('filePath').value;
                var thefile = fso.getFile(filepath);

Could you please let me know equivalent code for edge browser.



Solution 1:[1]

Edge doesn't support ActiveX. You can use File API <input type="file"> to choose files and then use XMLHttpRequest to upload files in modern browsers.

For more information you can refer to this thread and this code sample.

Solution 2:[2]

A lot has changed since the code you are trying to upgrade was created. Local Storage now exists and to download a file; (Use case somebody may need to save it for using it locally) a download attrib is added to the anchor html tag. The file needs to be made into a URL-Blob

<a id="download" download="example.png">
<button type="button" onClick="download()" class="UI">Download</button>
</a>
<script>
function download() {
   var download = document.getElementById("download");
   var image = document.getElementById("meme").toDataURL("image/png").replace("image/png", "image/octet-stream");
   download.setAttribute("href", image);
}
</script>

I would migrate to local-storage or IndexedDB API.

There is no drop in replacement for the activeX. because of security issues.

Major Differences

ActiveX allowed javascript to access a file to read or write, including being able to overwrite itself, anywhere on the hard drive.

HTML5 Allows reading and writting to localdata and several API for data including IndexDB. But file access is limited to what the user specifically uploads or for downloading into the download directory.

A Javascript WIKI page that replaces itself is no longer possible if you want it to overwrite itself. A Javascript WIKI page is possible using the IndexDB. Downloading the content is possible but limited for security reasons.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yu Zhou
Solution 2