From 496751d92c1dcca349cee6acbe9d6fd915696a5f Mon Sep 17 00:00:00 2001 From: jobin jose Date: Fri, 25 Apr 2025 08:53:57 +0530 Subject: [PATCH] to check code review --- src/utils/fileUpload.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/utils/fileUpload.ts diff --git a/src/utils/fileUpload.ts b/src/utils/fileUpload.ts new file mode 100644 index 0000000..28b3579 --- /dev/null +++ b/src/utils/fileUpload.ts @@ -0,0 +1,17 @@ +import * as fs from 'fs'; +import * as path from 'path'; + +export function uploadFile( + file: Express.Multer.File, + destinationPath: string, +): string { + const uploadPath = path.join(destinationPath, file.originalname); + + if (!fs.existsSync(destinationPath)) { + fs.mkdirSync(destinationPath); + } + + fs.writeFileSync(uploadPath, file.buffer); + + return uploadPath; +}