我正在编写一个程序来上传文件并使用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>
答案 0 :(得分:0)
尝试:
files=document.forms["myform"]["files"].files;