1
我正在编写一个程序来上传文件并使用md5对其进行编码。我收到此错误:未捕获的类型错误:未能在'FileReader'上执行'readAsBinaryString':参数1的类型不是'Blob'
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>
考虑添加到对象类型的引用,以便它为什么用'files'属性获得的文件列表的正确方法是显而易见的。 –