无法在OpenShift

时间:2016-09-12 02:09:27

标签: node.js express ckeditor openshift

我正在使用CKEditor插件将图像上传到我的OpenShift应用程序,但应用程序不会上传文件。它在本地工作正常,但我无法确定导致问题的原因。好像找不到目录了。

==> app-root / logs / nodejs.log< == POST / uploader?CKEditor = content& CKEditorFuncNum = 1& langCode = en - - ms - - 新路径:/ var / lib / openshift / 57cdb2770c1e660d0b000003 / app-root / runtime / repo / routes /../ public / uploads / test.jpg

{错误:    {[错误:ENOENT,打开'/var/lib/openshift/57cdb2770c1e660d0b000003/app-root/runtime/repo/routes/../public/uploads/test.jpg']      错误:34,      代码:'ENOENT',      路径:'/ var / lib / openshift / 57cdb2770c1e660d0b000003 /app-root / runtime / repo /routes /.. / public / uploads / test.jpg'}}

以下是处理上传的路线。

var express = require('express');
var router = express.Router();
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
var fs = require('fs');

router.post('/', multipartMiddleware, function(req, res) {

  fs.readFile(req.files.upload.path, function(err, data) {

    var newPath = __dirname + '/../public/uploads/' + req.files.upload.name;

    console.log('new Path:', newPath);

    fs.writeFile(newPath, data, function(err) {

      if (err) console.log({
        err: err
      });
      else {
        html = "";
        html += "<script type='text/javascript'>";
        html += "    var funcNum = " + req.query.CKEditorFuncNum + ";";
        html += "    var url     = \"/uploads/" + req.files.upload.name + "\";";
        html += "    var message = \"Uploaded file successfully\";";
        html += "";
        html += "    window.parent.CKEDITOR.tools.callFunction(funcNum, url, message);";
        html += "</script>";

        res.send(html);
      }
    });
  });
});

module.exports = router;

1 个答案:

答案 0 :(得分:0)

不确定OpenShift是如何工作的,但是你可能没有将你的public / uploads目录添加到项目/ repo /但是它安装在OpenShift服务器中。