simple-pdf-validator
v0.0.2
Published
A simple PDF validator
Downloads
5
Readme
Simple pdf validator
Simple PDF validations with multer files.
So you can assure people are not trying to upload something else to your server with pdf
extension.
Install
NPM:
npm install pdf-validator
Yarn
yarn add pdf-validator
Usage
NestJs example
import {
Controller,
Post,
UploadedFile,
UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { checkPdf } from 'pdf-validator'
@Controller()
export class UploadController {
@Post('upload')
@UseInterceptors(FileInterceptor('file'))
uploadFile(@UploadedFile() file: Express.Multer.File) {
checkPdf(file);
return { message: 'File uploaded successfully' };
}
}
Explanation
It works by checking some things:
- File size (if max provided)
- Mimetype
- Pdf version at start of file
- Ensure the EOF is actually the end of the file (7 chars for some versions, 6 chars for others.)