123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- const multer = require('multer');
- const path = require('path');
- require('dotenv').config();
- const DIR_UPLOAD = path.join(process.cwd(), process.env.DIR_UPLOAD);
- const storage = multer.diskStorage({
- destination: function (_req, _file, cb) {
- cb(null, DIR_UPLOAD);
- },
- filename: function (_req, file, cb) {
- cb(null, file.originalname);
- },
- });
- const uploadImage = multer({
- storage: storage,
- limits: { fileSize: 8000000 },
- fileFilter: (_req, file, cb) => {
- if (file.mimetype.includes('image')) return cb(null, true);
- cb(null, false);
- },
- });
- const uploadAudio = multer({
- storage: storage,
- limits: { fileSize: 20000000 },
- fileFilter: (_req, file, cb) => {
- if (file.mimetype.includes('audio')) return cb(null, true);
- cb(null, false);
- },
- });
- const uploadVideo = multer({
- storage: storage,
- limits: { fileSize: 200000000 },
- fileFilter: (_req, file, cb) => {
- if (file.mimetype.includes('video')) return cb(null, true);
- cb(null, false);
- },
- });
- const uploadFile = multer({
- storage: storage,
- limits: { fileSize: 200000000 },
- fileFilter: (_req, file, cb) => {
- if (file.mimetype.includes('application')) return cb(null, true);
- cb(null, false);
- },
- });
- module.exports = { uploadImage, uploadAudio, uploadVideo, uploadFile };
|