Hiya提前感谢您提供的任何帮助。 我正在使用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脚本,这是我得到的错误。我相信是与权限有关但我已经尝试了公共文件夹和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);
答案 0 :(得分:1)
你有没有想过这个?我也收到了EAccess错误。
要解决此问题,我执行了以下操作。
我必须确保包含path = require('path')
也不确定你的问题与Multer版本相比有多久,但我看起来在版本1.0.3中你必须multer = require('multer')
然后低于upload = multer()
1}}这也是你坚持配置信息的地方。
你最终得到了
var multer = require('multer'),
/*some config stuff for multer*/
Limits = { fileSize: 10 * 1024 * 1024, files:1 };
/* specify one file so ppl can't flood the server with infinite file
uploads or make it what you want but don't just leave it. Alternately
you can write the config stuff like the dest: value below. */
/*pass multer the configuration information and/or set config information*/
var upload = multer({dest: path.join(__dirname+'/uploads'),
limits: Limits
});
然后做app.post喜欢
app.post('/uploads', upload, function(req,res){
// expose req.file to a variable or do some process by which you send it to your database.
})
希望这会有所帮助。