簡體   English   中英

上載文件時Openshift NodeJS應用上的錯誤網關502

[英]Bad Gateway 502 on Openshift NodeJS app when uploading a file

我有一個基於NodeJS和AngularJS的應用程序,並將其推向openshift。 但是每次我嘗試上傳某些內容時,都會出現以下錯誤:

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

Angular發送數據如下:

$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);
    })

然后服務器使用busboy將其路由到文件以保存該文件:

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();

}

在Localhost上,一切正常,數據已保存到服務器。 但是我得到網關錯誤和此標頭的響應:

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

有人能幫助我嗎?

我已經解決了這個問題。 我發布它,以便有問題的人可以解決它。

openshift上的Web負載均衡器是HAproxy,並且由於內容類型服務器的響應與請求不同,因此上載有問題。 我從$ http從angular切換到XHR。 那解決了問題並且運作良好。 我根本沒有設置內容類型。 現在工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM