2016-06-16 3 views
1

안녕하세요! .. MEAN Stack에서 작업하는 초보자입니다. ng-file-upload를 사용하여 사진을 업로드하려고합니다. 여기 ng-file-upload가 진행 중에 멈 춥니 다.

app.controller('profilePicCtrl', ['Upload', '$scope', '$http', 
         function(Upload, $scope, $http){ 

    $scope.watch(function(){ 
     return $scope.file 
    }, function(){ 
     $scope.upload($scope.file); 
    }); 

    $scope.userID = localStorage.getItem('userID'); 
    $scope.upload = function(file){ 
     console.log("entro en upload"); 
     if(file){ 
      Upload.upload({ 
       url:'api/profile/edit', 
       method:'POST', 
       data: {userId: $scope.userID}, 
       file: file 
      }).progress(function(evt, status){ 
       console.log("dale puej mijo "); 
       console.log('percent: ' + parseInt(100.0 * evt.loaded/evt.total)); 
      }).success(function(data, status){ 
       console.log('archivo subido'); 
      }).error(function(error){ 
       console.log(error); 
      }) 
     } 
    }; 
}]); 

가 명시 적 코드 :

module.exports.updatePhoto = function(req, res){ 
    var file = req.file; 
    var userId = req.body.userId; 
    console.log("User "+userId+ " is submitting ", file.name); 
    } 

그리고 마지막으로 내가 컨트롤러 호출 서버 측 코드입니다 :

var multipart = require('connect-multiparty'); 
var multipartMiddleware = multipart(); 
var profileController = require('./routes/profile-controller'); 
... 
app.post('api/profile/edit', multipartMiddleware, profileController.updatePhoto); 

그에게 이것은 각 코드 컨트롤러를 통과하지 못하면 서버가 응답하지 않습니다. 미리 관심을 가져 주셔서 감사합니다.

답변

0

나는 'GET'과 다른 다른 방법을 사용하지 못하게하는 코드를 가지고있었습니다. 이 사람은 아래의 유죄이었다 :

if(req.method === "GET" || req.method === "POST"){ 
    if(!req.isAuthenticated()) { 
     res.redirect('/#login'); 
    }else{ 
     return next(); 
    } 
} 

대신 나는 next() 방법을 반환하지만 하나를 발견하지 무한 루프에 가서 내 코드를 일으키는 원인이 된 if 단지 req.method==='GET 문장에 있던 or 문장. 이제 or 문장으로 제 코드는 POST 메쏘드로갑니다.