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 ݽٕਸ ࢎਊ೧ࢲ ࢲߡܳ द੘ೡ ٸ ࢤࢿ೤פ׮
   222   223   224   225   226   227   228   229   230   231   232