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'屬性獲得的文件列表的正確方法是顯而易見的。 –