2015-01-07 2 views
1

나는 angularJs를 사용하여 서버에 http Post 요청을합니다. NodeJs 서버에 파일을 업로드 할 수는 있지만 요청에서 keywords을 가져 오는 방법을 알 수 없습니다.nodejs에서 양식 데이터 매개 변수를 가져 오는 중

클라이언트 코드 (AngularJS와)

 var file = $scope.myFile; 
     var uploadUrl = HOST_URL+"/filter-reports"; 

     var fd = new FormData(); 
     fd.append('file', file); 
     fd.append('keywords','searchkey1, searchkey2'); 
     $http.post(uploadUrl, fd, { 
      transformRequest: angular.identity, 
      headers: {'Content-Type': undefined} 
     }) 
     .success(function(data){ 
      console.log('Fetched the data .. '+data); 
     }) 
     .error(function(){ 
      console.log('could not fetch the data .. '); 
     }); 

나 Node.js를에 FormData 매개 변수를 추출하기 위해 알려 나는 NodeJs 새로운 오전으로 내가 잘못 가고 어딘지 알려 주시기 바랍니다.

답변

1

req.body.keywords 당신이 몸 파서 급행 사용하는 경우

1
  1. 는 노드 서버에 body-parser 모듈을 설치합니다.

  2. 그러면 서버에서 모듈 var bodyParser = require('body-parser');을 요청하십시오. 그러면 요청 본문이 구문 분석되어 본문 내부의 매개 변수에 액세스하게됩니다. 다음과 같이, 당신은 키워드 매개 변수를 얻을 수 있습니다 귀하의 게시물 요청에 대한 경로에서

  3. ,

    var keys=req.body.keywords;

관련 문제