2015-01-05 2 views
0

내 클라이언트 측 javascript에서 csv 파일을 게시 요청으로 내 노드 서버에 업로드하고 있습니다. nodejs 서버에서도 요청을 처리 할 수 ​​있습니다. 파일을 가져 와서 서버 측에서 파일 구문 분석을 도와주세요. 파일은 csv 파일이 될 것이므로 파일을 구문 분석하고 파일의 내용을 읽어야합니다.nodejs에서 양식 데이터 처리

아래의 서버 측뿐만 아니라 클라이언트 측에서 파일을 업로드 할 수있는 소스 코드 스 니펫이 첨부되어 있습니다. NodeJs 서버에서

myAngularApp.service('fileUpload', ['$http', function ($http) { 
    this.uploadFileToUrl = function(file, uploadUrl){ 
    var fd = new FormData(); 
    fd.append('file', file); 
    $http.post(uploadUrl, fd, { 
     transformRequest: angular.identity, 
     headers: {'Content-Type': undefined} 
    }) 
     .success(function(){ 
      // handling on success data 
     }) 
     .error(function(){ 
      // handling on error data 
     }); 
    } 

:

router.post('/filter-reports', function(req, res) { 
    console.log('Came inside the Node js router.. Now.. its all up to me to format the data....'); 
    console.log(req); 
}); 
+0

가능한 노드/익스프레스 파일 업로드 (http://stackoverflow.com/questions/23691194/node-express-file-upload) – callmekatootie

+0

당신은 약간의 정보를 주셨습니다. 콘솔을 할 수 있습니다. 로그 req.body 및 req.files에 파일이 있는지 확인하십시오. express.4.0 +에서는 다중 형식 데이터를 처리하기 위해 bodyparser를 사용할 수 없으므로이 질문을드립니다. – harryy000

답변

-1

난 당신이 다중/formdata 요청을 처리하기 위해 multer를 사용하지 않을 생각합니다.

위의 코드에서 언급

var multer = require('multer'); 
var storage = multer.diskStorage({ 
    destination: function (req, file, callback) { 
    callback(null, './public'); 
    }, 
    filename: function (req, file, callback) { 
    callback(null, file.fieldname + '-' + Date.now()); 
    } 
}); 

.

/public은 파일이 저장 될 디렉토리입니다. 당신은 그것을 바꿀 수 있고 파일 이름은 타임 스탬프와 함께 원래 파일 이름으로 바뀔 것입니다. 여기에는 선택 필드가 있습니다.

그런 다음, 당신이 당신의 파일 정보를 얻을 것이다하거나 파일 req.files.path가 사용됩니다 액세스하거나 파일을 저장하고 버퍼에 작업을하고 싶어하지 않으려면 웨이터하기 위해 시도해 req.file 또는 req.files에.