Fix FileUploadMiddleware formidable usage

This commit is contained in:
Alice Gaudon 2021-11-22 17:59:32 +01:00
parent 2e68cf8cae
commit e151c9c744
1 changed files with 3 additions and 3 deletions

View File

@ -1,16 +1,16 @@
import {NextFunction, Request, Response} from "express";
import IncomingForm from "formidable/Formidable.js";
import formidable, {Options} from "formidable";
import {FileError, ValidationBag} from "./db/Validator.js";
import Middleware from "./Middleware.js";
export default abstract class FileUploadMiddleware extends Middleware {
protected abstract makeForm(): IncomingForm;
protected abstract getFormidableOptions(): Options;
protected abstract getDefaultField(): string;
public async handle(req: Request, res: Response, next: NextFunction): Promise<void> {
const form = this.makeForm();
const form = formidable(this.getFormidableOptions());
try {
await new Promise<void>((resolve, reject) => {
form.parse(req, (err, fields, files) => {