简体   繁体   English

我正在尝试使用 javascript new fileReader() 读取文件

[英]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我正在尝试使用 javascript new fileReader()函数读取文件以将文件转换为二进制格式,但在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.根据您的需要替换 URL。 Refer this Wix Corvid Api Overview请参阅此 Wix Corvid Api 概述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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