feat: upload file

This commit is contained in:
cv
2021-05-27 23:00:32 +02:00
parent f887817a68
commit e891e7a538
8 changed files with 272 additions and 12 deletions
+23
View File
@@ -0,0 +1,23 @@
import multer from 'multer';
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads');
},
filename: function (req, file, cb) {
cb(null, Date.now() + '--' + file.originalname);
},
});
// filter only json
const filterJson = (req, file, cb) => {
if (file.mimetype.includes('application/json')) {
cb(null, true);
} else {
cb(null, false);
}
};
const uploadJson = multer({ storage: storage, fileFilter: filterJson });
export default uploadJson.single('jsondb');