要通过FileReader判断上传的文件是否为图片,可以使用FileReader读取文件内容,并判断文件的MIME类型是否为图片类型。 以下是一个示例代码,可以在文件上传时触发change事件,并检查上传的文件是否为图片类型: <input type="file" id="fileInput" onchange="checkFile(event)"> function checkFile(event) { const file = event.target.files[0]; const reader = new FileReader(); reader.onload = function() { const uint = new Uint8Array(reader.result); let bytes = []; uint.forEach((byte) => { bytes.push(byte.toString(16)); }) const hex = bytes.join('').toUpperCase(); const fileType =...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile