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

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	},
           });
           router.post('/room/:id/gif',	upload.single('gif'),	async	(req,	res,	next)	=>	{
           		try	{
           				const	chat	=	await	Chat.create({
           						room:	req.params.id,
           						user:	req.session.color,
           						gif:	req.file.filename,
           				});
           				req.app.get('io').of('/chat').to(req.params.id).emit('chat',	chat);
           				res.send('ok');
           		}	catch	(error)	{
           				console.error(error);
           				next(error);
           		}
           });

           module.exports	=	router;




          ੢੄ ੉޷૑ স۽٘৬ ߑध੉ эणפ׮  VQMPBET ಫ؊ী ࢎ૓ਸ ੷੢ೞҊ  ౵ੌݺী ఋ੐झఙ೐ %BUF OPX()

         )ܳ ࠢ੉Ҋ   .#۽ ਊ۝ਸ ઁೠ೮णפ׮  ౵ੌ੉ স۽٘ػ റীח ղਊਸ ؘ੉ఠ߬੉झী ੷੢ೞҊ  ߑ উী ੓
         ח ݽٚ ࣗ௄ী ଻౴ ؘ੉ఠܳ ࠁշפ׮

         ੉ઁ ੉޷૑ܳ ઁҕೡ VQMPBET ಫ؊ܳ express.static ޷ٜਝয۽ োѾ೧ࠇद׮


          app.js
           ...
           app.use(express.static(path.join(__dirname,	'public')));
           app.use('/gif',	express.static(path.join(__dirname,	'uploads')));
           app.use(express.json());
           ...




         ੉ઁ (*' ౵ੌਸ ৢܾ ࣻ ੓णפ׮  ଻౴ਸ ૌѹࠁࣁਃ
   553   554   555   556   557   558   559   560   561   562   563