Aditya26Das / Backend-project

0 stars 0 forks source link

Error: ENOENT: no such file or directory #2

Closed Aditya26Das closed 5 months ago

Aditya26Das commented 5 months ago

As soon as I provide a local file path for the avatar and coverPage and run on postman I find the error Error: ENOENT: no such file or directory...

techwizard31 commented 5 months ago

As soon as I provide a local file path for the avatar and coverPage and run on postman I find the error Error: ENOENT: no such file or directory...

import multer from "multer"; import fs from "fs"; import path from "path"; import { fileURLToPath } from "url";

// Get the current file path and directory name in ES modules const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(__filename);

// Define the directory where files will be stored const tempDir = path.join(__dirname, '../public/temp');

// Ensure the directory exists if (!fs.existsSync(tempDir)) { fs.mkdirSync(tempDir, { recursive: true }); }

// Configure multer storage const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, tempDir); }, filename: function (req, file, cb) { cb(null, file.originalname); } });

// Create the multer middleware export const upload = multer({ storage });