【问题标题】:Uncaught TypeError: Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob'未捕获的类型错误:无法在“FileReader”上执行“readAsBinaryString”:参数 1 不是“Blob”类型
【发布时间】:2016-01-02 04:28:48
【问题描述】:

我正在编写一个程序来上传文件并使用 md5 对其进行编码。我收到此错误:

Uncaught TypeError: Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob'.

我做错了什么?

<!DOCTYPE html>
<head>
<head>
<meta charset="UTF-8">
<script>
function handleFiles() {
    var md5;
    files=document.forms["myform"]["files"].value;
    var reader = new FileReader();
    reader.onload = function() {
        md5 = binl_md5(reader.result, reader.result.length);
        console.log("MD5 is " + md5);
    };
    reader.onerror = function() {
        console.error("Could not read the file");
    };
    reader.readAsBinaryString(files[0]);    
 }
 </script>
</head>
<body>

<form name="myform" id="myform" method="post" action="" enctype="multipart/form-data">
    <input type="file" name="files">
    <input type="submit" value="upload" onclick="handleFiles()">
</form>
</body>
</html>

【问题讨论】:

    标签: javascript html file-upload md5


    【解决方案1】:

    尝试:

    files=document.forms["myform"]["files"].files;
    

    【讨论】:

    • 考虑添加对对象类型的引用,以便清楚为什么使用files 属性是获取文件列表的正确方法。
    猜你喜欢
    • 1970-01-01
    • 2015-12-07
    • 2017-06-24
    • 2022-10-07
    • 2023-03-04
    • 2018-04-01
    • 2016-02-10
    • 2021-12-04
    相关资源
    最近更新 更多