From 323b0df4f322cff47cdf47f07740c216930aaaa1 Mon Sep 17 00:00:00 2001 From: pociej Date: Thu, 25 Apr 2024 12:39:43 +0200 Subject: [PATCH] fix: mkdir temp #38 --- backend/src/services/file/routes.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/src/services/file/routes.ts b/backend/src/services/file/routes.ts index 371e4e5..d77a46e 100644 --- a/backend/src/services/file/routes.ts +++ b/backend/src/services/file/routes.ts @@ -6,6 +6,7 @@ import { pipeline } from "node:stream"; import fs from "node:fs"; import { fileURLToPath } from "url"; import { v4 as uuidv4 } from "uuid"; +import { mkdir } from "node:fs/promises"; const DIR_NAME = fileURLToPath(new URL("../../../../temp", import.meta.url)); export const fileService = fastifyPlugin( @@ -24,6 +25,12 @@ export const fileService = fastifyPlugin( reply.code(400).send({ message: "No file uploaded" }); return; } + + try { + await mkdir(DIR_NAME); + } catch (e) { + console.log("Error creating directory", e); + } //accoumulate the file in memory await util.promisify(pipeline)( data.file,