프로그래밍/Node.js

Node.js - connect.multipart() will be removed in connect 3.0 해결법

가카리 2014. 12. 27. 13:36
반응형

If you are using the bodyParser middleware for handling forms, you must be getting this warning message in your Express app.

만약 bodyParser 미들웨어를 사용하면 다음의 경고 메시지를 받는다.

 

connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0

 

Why this warning and how do you resolve it?

이 경고 메시지를 없애는 법은?

 

 

bodyParser는 connect.json(), connect.urlencoded()와 connect.multipart()이 합쳐진 미들웨어이다. Connect 3.0 에서 개발자는 개개의 미들웨어를 따로 include를 해야한다.

 

 

그러나 connect.multipart()에는 보안 관련 문제가 있다. 그래서 이것은 connect.limit()에 대해 경고 메시지가 뜰 것이다.

 

You will need to find an alternative for connect.multipart(). You might come across formidable, multiparty, and busboy in the process.

 

   connect.multpart()를 대체하기 위한 것이 필요하다.

 

 

   busboy의 경우 효율적이긴하나 Node.js 개발자에게는 좀 복잡하다.

 

그래서 connect.multipart()를 대체하는 것으로 Multer를 소개한다.

$ npm install multer

var multer = require('multer');//이 소스를 맨 위에

And then, add it in the middleware stack along with the other form parsing middleware.

 

그리고 다음의 소스를 자례로 추가시켜준다.

app.use(express.json());

app.use(express.urlencoded()); app.use(multer({ dest: './uploads/' }));

 

 

connect.json() handles application/json
connect.urlencoded() handles application/x-www-form-urlencoded
multer() handles multipart/form-data

For details about Multer and its options, visit the project page on GitHub.

 

 

출처 : http://expressjs-book.com/forums/topic/replacement-for-bodyparser-connect-multipart/

반응형