Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nextjs multer rename 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)
        }
    }),
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert number to word js 
Javascript :: set js 
Javascript :: refresh a page in the browser node js 
Javascript :: generate html with javascript 
Javascript :: rm -rf node_modules 
Javascript :: javascript canvas reset transform 
Javascript :: notice before reload js 
Javascript :: classname did not match server next js styled components 
Javascript :: react refresh 404 error 
Javascript :: exclude file types from formater vscode 
Javascript :: how to draw ellipse in javascript canvas 
Javascript :: how to make @click in router-link vuejs 
Javascript :: expressjs 
Javascript :: owl carousel next previous button 
Javascript :: sort javascript number array with duplicates 
Javascript :: sanitizing user input javascript 
Javascript :: install react router dom with npm 
Javascript :: capitalize first letter of string javascript 
Javascript :: get unique array javascript 
Javascript :: javascript Inserting values in between an array 
Javascript :: javascript hashmap 
Javascript :: how to get class name in jquery 
Javascript :: nodejs mysql getting the id of an inserted row 
Javascript :: javascript number length 
Javascript :: javascript open page 
Javascript :: javascript get element by rel attribute 
Javascript :: typeof 
Javascript :: reactjs hello world 
Javascript :: start date and end date validation antd 
Javascript :: javascript long integer 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =