如何解决.. ?? TypeError:无法读取属性' FileSystem'未定义的

时间:2016-07-27 06:57:41

标签: node.js

我试图在nodejs中拆分并合并上传的pdf文件,而我正在运行我收到错误" TypeError:无法读取属性' FileSystem'未定义"," ReferenceError:FS未定义"帮我解决一下。

 var express = require('express');
 var path = require('path');
 var favicon = require('serve-favicon');
 var logger = require('morgan');
 var cookieParser = require('cookie-parser');
 var bodyParser = require('body-parser');
 var fileUpload = require('express-fileupload');
 var routes = require('./routes/index');
 var users = require('./routes/users');
 var gm = require('gm');
 var app = express();
 var fs =require('fs');

 app.use(fileUpload());

 app.post('/upload', function(req, res) {
    var sampleFile;
    console.log("upload");
    if (!req.files) {
        res.send('No files were uploaded.');
        return;
    }

    new FS.Store.FileSystem("thumbs", {
        transformWrite: function(fileObj, readStream, writeStream) {
            gm(readStream, fileObj.name() + '[0]').resize('100',         '100').stream('png').pipe(writeStream);
        },
        beforeWrite: function (fileObj) {
            return {
                extension: 'pdf',
                type: 'pdf'
            };
        },
        path: "./public/images/",
    })

    sampleFile = req.files.sampleFile;
    console.log("statrttttttttt");
    console.log(req);
    var fileName=sampleFile.name;

    sampleFile.mv('./public/images/'+fileName, function(err) {
        if (err) {
             res.status(500).send(err);
        }
        else {
            res.send("<html><h1><object data='/images/"+fileName+"'</h1></object></html>");
        }
    });
})
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/js',express.static(path.join(__dirname, 'public/javascripts')));

app.use('/', routes);
app.use('/users', users);

module.exports = app;

1 个答案:

答案 0 :(得分:0)

new FS.Store.FileSystem("thumbs", {
      transformWrite: function(fileObj, readStream, writeStream) {
        gm(readStream, fileObj.name() + '[0]').resize('100', '100').stream('png').pipe(writeStream);
      },

javascript是个案例。您引用fs模块作为:

var fs = require('fs');

并使用FS