Page 227 - Nodejs 교과서 개정2판
P. 227
۞ೠ ಬਸ ా೧ স۽٘ೞח ੌ CPEZ QBSTFS۽ח ܻೡ ࣻ হҊ य ೧ࢳ ೞӝب য۰۽ NVMU
FSۄח ٜਝযܳ ٮ۽ ࢎਊೞݶ ಞܻפ NVMUFSܳ ࢸפ
콘솔
$ npm i multer
NVMUFS ಁః উীח ৈ۞ ઙܨ ٜਝযо ٜয णפ ٜਝযܳ ಝࠁӝ ী ӝࠄੋ ࢸࠗఠ ঌ
ইࠇद
const multer = require('multer');
const upload = multer({
storage: multer.diskStorage({
destination(req, file, done) {
done(null, 'uploads/');
},
filename(req, file, done) {
const ext = path.extname(file.originalname);
done(null, path.basename(file.originalname, ext) + Date.now() + ext);
},
}),
limits: { fileSize: 5 * 1024 * 1024 },
});
multer ೣࣻ ੋࣻ۽ ࢸਸ ֍णפ storage ࣘࢿীח য٣ী destination যڃ ܴਵ۽ filename
ೡܳ ֍णפ destinationҗ filename ೣࣻ req ݒѐ߸ࣻীח ਃী ೠ ࠁо file ёীח স
۽٘ೠ ੌী ೠ ࠁо णפ done ݒѐ߸ࣻח ೣࣻੑפ ߣ૩ ੋࣻীח ী۞о ݶ ী۞ܳ ֍
Ҋ ف ߣ૩ ੋࣻীח पઁ ҃۽ա ੌ ܴਸ ֍যݶ ؾפ reqա file ؘఠܳ оҕ೧ࢲ doneਵ۽ ֈ
ӝח ഋधੑפ
അ ࢸਵ۽ח VQMPBETۄח ಫ؊ী [파일명+현재시간.확장자] ੌݺਵ۽ স۽٘ೞҊ णפ അ दр
ਸ ֍যח ਬח স۽٘ೞח ੌݺ Ҁח Ѫਸ ݄ӝ ਤ೧ࢲੑפ
limits ࣘࢿীח স۽٘ী ೠ ઁೠ ࢎ೦ਸ ࢸೡ ࣻ णפ ੌ ࢎૉ fileSize ߄ ױਤ ח .#
۽ ઁೠ೧فणפ
݅ ਤ ࢸਸ पઁ۽ ഝਊೞӝ ਤ೧ࢲח ࢲߡী VQMPBET ಫ؊о ԙ ઓ೧ঠ פ হݶ ٜ݅যѢ
ա җ э GT ݽٕਸ ࢎਊ೧ࢲ ࢲߡܳ दೡ ٸ ࢤࢿפ