Skip to content

Instantly share code, notes, and snippets.

@movii
Last active November 28, 2017 09:22
Show Gist options
  • Save movii/000a699f4043c33dec211903e2a32f01 to your computer and use it in GitHub Desktop.
Save movii/000a699f4043c33dec211903e2a32f01 to your computer and use it in GitHub Desktop.
笔记:使用 JavaScript 识别文件 MIME TYPE 类型:2. 对比文件类型的操作
FR.onload = (e) {
let af = e.target.result
, view = new DataView(af)
, first4Byte = view.getUint32(0, false);
let hexValue = Number(first4Byte).toString(16);
switch (hexValue) {
case 'FFD8FFE0':
case 'FFD8FFE1':
case 'FFD8FFE2':
case 'FFD8FFE3':
console.log('is JPEG/JPG');
break;
default:
console.log('undefined');
break;
}
};
FR.readAsArrayBuffer(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment