简体   繁体   中英

I am trying to read the file using javascript new fileReader()

I am trying to read the file using javascript new fileReader() function to convert the file in to binary format but is not supporting in Wix

please support us to resolve this issue to overcome it

var fr=new FileReader(); 

Hope This helps you :-

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
</head>
<body>

  <input type="file" />
  <!-- writing JavaScript inside html -->
       
    
     <body>
    
      <input type="file" />
      <!-- writing JavaScript inside html -->
      <script>
            const filename = document.querySelector('input[type="file"]');
    
            filename.addEventListener('change', function (){
            // Creating a FileReader object using the constructor.
    
            const filereader = new FileReader();
            // Reading a file as plain text
    
            filereader.readAsText(filename.files[0]);
            // Call this function to print the contents of the file
            // once the file has been read.
    
            filereader.onload = function {
                console.log(filereader.result);
            };
            // Print the error incase there is one
    
            filereader.onerror = function {
                console.log("Error: ", filereader.error);
            };
    },false);
      </script>
    </body>
</body>
</html>

I think i have found a solution for you :-

try this

/* global FileReader */

$w.onReady(function () {
     const fileReader = new FileReader();

fetch('https://static.wixstatic.com/media/e3b156_8646d72618e3420db36dba9156d0b8e7~mv2.jpg/v1/fit/w_512,h_586/o_0.jpeg')
        .then(response => response.blob())
        .then(blob => fileReader.readAsArrayBuffer(blob));

    fileReader.onload = function () {
        // your buffer array here. But why you need it? )))
        console.log(fileReader.result);
    }
})

Replace URL according to your needs. Refer this Wix Corvid Api Overview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM