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; +}