我想在node.js中开发和应用,我可以在我的页面中上传视频并在数据库中存储该视频的链接(mongodb)。当我点击//链接时,vedio应该得到display.also我shud能够显示在页面上传的所有//视频。我试图编码上传照片
//new show photo code
app.get('/photos', function(req, res) {
photos.list(function(err, photo_list) {
res.render('photos/index', {locals : {
photos: photo_list
}});
});
});
app.get('/photos/new', function(req, res){
res.render('photos/new', {
locals: {
title: 'New File Upload'
}
});
});
app.post('/photos', function(req, res) {
req.setEncoding('binary');
var parser = multipart.parser();
parser.headers = req.headers;
var ws;
parser.onpartBegin = function(part) {
consol.log('inside begin');
ws = fs.createWriteStream(__dirname + '/static/upload/photos.' + part.filename)
ws.on('error', function(err) {
throw err;
});
};
parser.onData = function(data) {
ws.write(data);
};
parser.onPartEnd = function() {
ws.end();
parser.close();
console.log('file successfully uploaded');
res.redirect('/photos');
};
req.on('data', function(data) {
console.log('shud not go here');
parser.write(data);
});
});
//任何人都可以向我发送相同的代码,或者发现我正在做//wrong.....answer立即要求....