Openshift多部分图像上传返回502代理错误

时间:2016-04-17 18:06:16

标签: node.js express openshift multer

我正在尝试使用我的Node.js后端将图像上传到Openshift。代码在我的本地服务器中正常工作,但使用Postman向Openshift发送请求会导致它等待几秒钟后跟着:

502 Proxy error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request 
Reason: 
        Error reading from remote server

app.js:

var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var app = express();
var multer = require('multer');
var upload = multer({dest: process.env.OPENSHIFT_DATA_DIR});
var busboy = require('connect-busboy');

app.post('/auth/profilePic',upload.single('profilepic'),function(req,res,next){
    userController.setProfilePic(req,res);

 });

控制器/ user.js的:

var dirName = process.env.OPENSHIFT_DATA_DIR;
exports.setProfilePic = function(req,res){
   User.findOne({email: req.headers['x-auth-email']}, function (err, user) {
           if (err) {
               res.send(err);
           }
           if (!user) {
               res.status(404).send({message: 'user not found'});
           }
           else if (user.password == req.decodedToken) {
               fs.rename(dirName + req.file.filename,dirName + user._id, function(err){
                   if (err) {
                       res.send(err);
                   }
                   else {
                       user.profilePicture = dirName + user._id;
                       user.save();
                       res.status(200).send({message:'save OK'});
                   }
               });
           }
       });
   };

0 个答案:

没有答案