未捕获的TypeError:无法在'FileReader'上执行'readAsBinaryString':参数1不是'Blob'类型

时间:2015-10-05 13:31:42

标签: javascript html file-upload md5

我正在编写一个程序来上传文件并使用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>

1 个答案:

答案 0 :(得分:0)

尝试:

files=document.forms["myform"]["files"].files;
相关问题