fake 이미지, 동영상 파일 검증하는 로직 (중간단계 개발중)

This commit is contained in:
leejinho 2020-02-13 17:24:00 +09:00
parent fc5f91d380
commit 215a4dd662
2 changed files with 63 additions and 0 deletions

View File

@ -223,6 +223,65 @@ export class CommonApiService {
}; };
} }
public mimeCheckForImageAndVideoFiles(files: File[]) {
files.forEach(file => {
console.log(file);
const fileReader = new FileReader();
fileReader.onloadend = () => {
const arr = new Uint8Array(fileReader.result as ArrayBuffer).subarray(
0,
4
);
let header = '';
for (let i = 0; i < arr.length; i++) {
header += arr[i].toString(16);
}
console.log('File header: ' + header);
// Check the file signature against known types
var type = 'unknown';
// http://forensic-proof.com/archives/300?ckattempt=1
if (header.startsWith('89504e47')) {
// 89504E470D0A1A0A
type = 'image/png';
} else if (header.startsWith('47494638')) {
// 474946383761
// 474946383961
type = 'image/gif';
} else if (header.startsWith('ffd8ffe')) {
// ffd8ffe0
// ffd8ffe1
// ffd8ffe2
// ffd8ffe8
type = 'image/jpeg';
} else if (header.startsWith('424d')) {
type = 'image/bmp';
} else if (header.startsWith('4d4d') || header.startsWith('4949')) {
type = 'image/tiff';
} else if (header.startsWith('4F676753')) {
// 4F67675300020000
type = 'image/ogg';
} else if (header.startsWith('38425053')) {
// 38 42 50 53
type = 'image/psd';
} else if (header.startsWith('25504446')) {
// 38 42 50 53
type = 'image/ai';
} else if (header.startsWith('52494646')) {
// avi
type = 'video/x-msvideo';
} else if (header.startsWith('00000018')) {
// 0000001866747970
type = 'video/x-msvideo';
}
console.log('type', type);
};
fileReader.readAsArrayBuffer(file);
});
}
public fileTalkShare( public fileTalkShare(
req: FileTalkShareRequest req: FileTalkShareRequest
): Observable<FileTalkShareResponse> { ): Observable<FileTalkShareResponse> {

View File

@ -1107,6 +1107,10 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
} }
} }
// this.commonApiService.mimeCheckForImageAndVideoFiles(
// fileUploadItems.map(fui => fui.file)
// );
const checkExt = this.commonApiService.acceptableExtensionForFileTalk( const checkExt = this.commonApiService.acceptableExtensionForFileTalk(
fileUploadItems.map(fui => FileUtil.getExtension(fui.file.name)) fileUploadItems.map(fui => FileUtil.getExtension(fui.file.name))
); );