Page 228 - Nodejs 교과서 개정2판
P. 228

const	fs	=	require('fs');


           try	{
           		fs.readdirSync('uploads');
           }	catch	(error)	{
           		console.error('uploads	폴더가	없어	uploads	폴더를	생성합니다.');
           		fs.mkdirSync('uploads');
           }




         ࢸ੿੉ ՘աݶ upload ߸ࣻо ࢤӝחؘ  ৈӝী ׮নೠ ઙܨ੄ ޷ٜਝযо ٜয ੓णפ׮

         ݢ੷ ౵ੌਸ ೞա݅ স۽٘ೞח ҃਋ NVMUJQBSU IUNMҗ э਷ ҃਋ ীח TJOHMF ޷ٜਝযܳ ࢎਊ೤פ׮




           app.post('/upload',	upload.single('image'),	(req,	res)	=>	{
           		console.log(req.file,	req.body);
           		res.send('ok');
           });




         single ޷ٜਝযܳ ۄ਋ఠ ޷ٜਝয খী ֍যفݶ  multer ࢸ੿ী ٮۄ ౵ੌ স۽٘ റ req.file ё୓о ࢤࢿ

         ؾפ׮  ੋࣻח input కӒ੄ name੉ա ಬ ؘ੉ఠ੄ ః৬ ੌ஖ೞѱ ֍ਵݶ ؾפ׮  স۽٘ ࢿҕ द Ѿҗח req.f
         ile ё୓ উী ٜয ੓णפ׮  req.bodyীח ౵ੌ੉ ইצ ؘ੉ఠੋ title੉ ٜয ੓णפ׮


         req.file ё୓ח ׮਺җ э੉ ࢤ҂णפ׮




           {
           		fieldname:	'img',
           		originalname:	'nodejs.png',
           		encoding:	'7bit',
           		mimetype:	'image/png',
           		destination:	'uploads/',
           		filename:	'nodejs1514197844339.png',
           		path:	'uploads\\nodejs1514197844339.png',
           		size:	53357
           }




         ৈ۞ ౵ੌਸ স۽٘ೞח ҃਋ )5.-੄ input కӒীח multipleਸ ॳݶ ؾפ׮

          multipart.html

           <form	id="form"	action="/upload"	method="post"	enctype="multipart/form-data">
   223   224   225   226   227   228   229   230   231   232   233