2

I'm using keystone.js, which uses express.js and jade, and the pdf-extract npm module.

I'm trying to setup an upload form which extracts a PDF and renders the text in a view in keystone.js.

I'm having trouble rendering the view on pdf-extract processor complete event. It looks like I have recursion. I have this route, upload.js

exports = module.exports = function(req, res) {

var view = new keystone.View(req, res),
    locals = res.locals;

// Set locals
locals.section = 'upload';
locals.formData = req.body || {};
locals.validationErrors = {};

view.on('post', { action: 'upload' }, function(next) {
       ...
       ...file upload code
       ...
       var processor = pdf_extract(absolute_path_to_pdf, options, function(err) {
         if (err) {
           res.end(util.inspect(err));
         } 
       });
       processor.on('complete', function(data) {
         view.render('upload', {jadeVar:data.text_pages});
         next();
       }); //on processor.complete
    });  //on view.post
view.render('upload');  //render on no post

This outputs about two dozen errors from pdf-extract about uploaded file not found in a recursive fashion.

If I do this:

processor.on('complete', function(data) {
  res.end(util.inspect(data.text_pages));
});

I get the extracted pdf text I want directly to the browser without the "upload" view. I am trying to take that output and send it to the "upload" view.

4

1 に答える 1

1

view.render の代わりに res.render を使用するように完了イベントのプロセッサを変更しました

processor.on('complete', function(data) {
     res.render('upload', {jadeVar:data.text_pages});
     next();
   }); //on processor.complete

これは変数のスコープの問題であり、ビューが定義されていないと思いますか?

keystone/lib/view.js を見て、これを見つけました

于 2014-04-08T15:41:28.780 に答える