Home > Blockchain >  Migrating to Edge Browser - file upload not working
Migrating to Edge Browser - file upload not working

Time:05-16

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.

CodePudding user response:

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.

CodePudding user response:

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()" >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.

  • Related