const multer = require('multer')
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads/')
},
filename: function (req, file, cb) {
cb(null, file.filename + '-' + Date.now())
}
})
const upload = multer({ storage: storage })
// For Single uploads
router.route('/upload').post(upload.single('file'), (req, res, next) => { return res.json(req.file) })
// For multiple file uploads (using FormData)
router.route('/upload').post(upload.array('file[]'), (req, res, next) => { return res.json(req.file) })
const multer = require('multer')
const addZero = (i: string | number) => {
if (i < 10) {
i = "0" + i;
}
return i;
}
const upload = multer({
storage: multer.diskStorage({
destination: EMS_ITEM_MASTER_FILE_FOLDER,
filename: function (req, file, cb) {
let originalFileName = file.originalname;
let originalFileFrgs = originalFileName.split(".");
const today = new Date();
const fullYear = today.getFullYear();
const month = addZero(today.getMonth());
const day = addZero(today.getDate());
const Hours = today.getHours();
const Mins = today.getMinutes();
const Secs = today.getSeconds();
let fileSuffix = [fullYear, month, day].join("") + "-" + [Hours, Mins, Secs].join("");
originalFileFrgs[0] = originalFileFrgs[0] + '#' + fileSuffix;
file.filename = originalFileFrgs.join(".");
cb(null, file.filename)
}
}),
});