/
Moss
/
Diplom
Обзор
Документация
Войти
/
Moss
/
Diplom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
server/src/config/cloudinary.ts
39 строк
1 KB
Kursovaya
lol
08 июн 2025, 18:06
08 июн 2025, 18:06
c28cde0
Код
Авторство
О чём код?
import multer from 'multer'; import path from 'path'; import { v4 as uuidv4 } from 'uuid'; import fs from 'fs'; // Создаем директорию для загрузки, если она не существует const uploadDir = path.join(__dirname, '../../uploads/cars'); if (!fs.existsSync(uploadDir)) { fs.mkdirSync(uploadDir, { recursive: true }); } // Configure storage const storage = multer.diskStorage({ destination: (req, file, cb) => { cb(null, uploadDir); }, filename: (req, file, cb) => { const uniqueFilename = `${uuidv4()}${path.extname(file.originalname)}`; cb(null, uniqueFilename); } }); // File filter const fileFilter = (req: Express.Request, file: Express.Multer.File, cb: multer.FileFilterCallback) => { if (file.mimetype.startsWith('image/')) { cb(null, true); } else { cb(new Error('Only image files are allowed')); } }; export const upload = multer({ storage: storage, fileFilter: fileFilter, limits: { fileSize: 10 * 1024 * 1024, // 10MB limit files: 5 // максимум 5 файлов } });