2014-11-18 5 views
0

NodeJS 및 AngularJS를 기반으로하는 애플리케이션이 있으며이를 opensshift로 푸시했습니다. 파일에파일을 업로드 할 때 Openshift NodeJS 앱의 게이트웨이 502가 잘못되었습니다.

$scope.newFile = function() { 
    $scope.id = $scope.group._id; 
    var fd = new FormData(); 
    var file = $scope.files[0]; 
    fd.append('file', file); 
    if (file.type!="application/pdf"){ 
     mvNotifier.error("Nur PDF Dateien sind akzeptiert."); 
     return; 
    }  
    $http.post('/api/upload/file', fd, { 
     transformRequest: angular.identity, 
     headers:{'Content-Type': undefined} 
    }) 
    .success(function(d) { 
     var data = { 
      name: file.name, 
      description: $scope.descriptionfile 
     } 
     mvNotifier.notify("Bis hier hin klappt alles"); 
     console.log("sucess on uploading "); 

     mvFactory.POST(data, mvGroup, {_place:"file", _id:$scope.id}).then(function(data) { 
      $scope.newfile=false; 
      $scope.group.files.push({name:file.name, description:$scope.descriptionfile}); 
      mvNotifier.notify("Datei hochgeladen"); 
     }, function(reason) { 
      mvNotifier.error("reason"); 
     }) 
    }) 
    .error(function(data,status,header) { 
     mvNotifier.error("Upload hat nicht funktioniert.") 
     console.log("data", data); 
     console.log("status", status); 
     console.log("header", header); 
    }) 

그리고 서버 경로를 저장하는 웨이터를 사용하여 :

POST http://www.domain.de/api/upload/file 502 (Bad Gateway) 

각도는 다음과 같이 데이터를 전송 :하지만 매번 나는 다음과 같은 오류가 뭔가를 업로드하려고

uploadFile: function(req,res) { 
    console.log("req",req.files); 
    if (process.env.OPENSHIFT_DATA_DIR!= undefined) { 
     var cPath = process.env.OPENSHIFT_DATA_DIR; 
    } else { 
     var cPath = path.resolve('..', 'data'); 
    } 
    var busboy = new Busboy({ headers: req.headers }); 
    req.pipe(busboy); 
    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { 
     var wPath = cPath + '/uploads/documents'; 
     file.pipe(fs.createWriteStream(wPath + '/' + filename)); 

     file.on('end', function() { 
      console.log('File [' + fieldname + '] Finished'); 
     }); 
    }); 
    busboy.on('finish', function() { 
     console.log('Done parsing form!'); 
    }); 
    res.status(200).end(); 

} 

로컬 호스트에서 모든 것이 정상적으로 작동하고 데이터가 서버에 저장됩니다. 하지만 나쁜 게이트웨이와이 헤더의 응답을받습니다.

<title>502 Bad Gateway</title> 
</head><body> 
<h1>Bad Gateway</h1> 
<p>The proxy server received an invalid response from an upstream server.<br /> 

나를 도와 줄 수있는 사람이 있습니까?

답변

1

문제를 해결했습니다. 문제가있는 사람이 해결할 수 있도록 게시합니다.

openshift의 웹 부하 분산 장치가 HAproxy이고 콘텐츠 형식으로 인해 서버의 응답이 요청과 동일하지 않기 때문에 업로드에 문제가 있습니다. 나는 각도에서 XHR로 $ http에서 전환했다. 그게 문제를 해결하고 잘 작동합니다. 내용 유형 i는 전혀 설정하지 않았습니다. 이제는 잘 작동합니다.