您好,提前感谢您提供的任何帮助。我正在使用 C9.io、node、express、multer、gridfs-stream。我得到:
/home/ubuntu/workspace/node_modules/multer/index.js:25
mkdirp(dest, function(err) { if (err) throw err; });
Error: EACCES, mkdir '/uploads'
我运行 server.js 脚本,这就是我得到的错误。我相信这与权限有关,但我尝试过 chown 公用文件夹和 chmod ax,你们还有其他关于该怎么做的建议吗?仍然得到同样的错误。我的代码是 server.js
app.use('/uploads', express.static(__dirname + '/public/uploads'));
app.use(multer({dest: '/uploads/'}));
app.use(methodOverride());
app.get('/form',function (req,res){
res.render('form');
});
app.get('/api/taxis', function(req,res){
taxiModel.Taxi.find({}).exec(function(error,collection){
res.send(collection);
});
});
// app.get('user/:name', function(req,res){
// taxiModel.Taxi.find({name:req.param.nmae},function(err,docs){
// if(err)res.json(err);
// else res.render();
// }
// });
app.get('*', function (req,res){
res.render('index');
});
app.post('/new',function(req,res){
var dirname = require('path').dirname(__dirname);
var filename = req.files.dnimgfront.name;
var path = req.files.dnimgfront.path;
var type = req.files.dnimgfront.mimetype;
var gfs = Grid(conn.db);
var read_stream = fs.createReadStream(dirname + '/' + path);
var writestream = gfs.createWriteStream({filename: filename});
read_stream.pipe(writestream);
});
mongoose.connect('mongodb://jsrosas:12345@ds031721.mongolab.com:31721/taxis');
var conn=mongoose.connection;
conn.once('open', function(){
console.log('connected to mongodb succesfully!');
});
app.listen(process.env.PORT, process.env.IP);