0
我試圖拆分和合並上載的pdf文件在nodejs中,而我正在運行時出現錯誤「TypeError:無法讀取未定義的屬性'FileSystem'」,「ReferenceError:FS不是定義「幫助我解決它。如何解決它.. ?? TypeError:無法讀取未定義的屬性'FileSystem'
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;
如果我使用FS而不是FS也出現錯誤「TypeError:無法讀取屬性'FileSystem'的未定義」 –
我相信你使用這個[插件](https://github.com/CollectionFS/Meteor -CollectionFS)。你有它作爲你的依賴安裝?另外,我注意到它已被棄用,爲什麼你不使用本地節點功能來保存文件? [檢查此](http://stackoverflow.com/questions/2496710/writing-files-in-node-js) –