mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-22 01:31:30 +03:00
27 lines
626 B
JavaScript
27 lines
626 B
JavaScript
const fs = require('fs');
|
|
const { join } = require('path');
|
|
const multer = require('multer');
|
|
const uuid = require('uuid');
|
|
|
|
const storage = multer.diskStorage({
|
|
destination: (req, file, cb) => {
|
|
cb(null, './data/uploads');
|
|
},
|
|
filename: (req, file, cb) => {
|
|
cb(null, Date.now() + '--' + file.originalname);
|
|
}
|
|
})
|
|
|
|
const supportedTypes = ['jpg', 'jpeg', 'png'];
|
|
|
|
const fileFilter = (req, file, cb) => {
|
|
if (supportedTypes.includes(file.mimetype.split('/')[1])) {
|
|
cb(null, true);
|
|
} else {
|
|
cb(null, false);
|
|
}
|
|
}
|
|
|
|
const upload = multer({ storage, fileFilter });
|
|
|
|
module.exports = upload.single('icon'); |