我想知道如何查看玉上傳的圖片下面是我的一些示例代碼的下方如何查看玉上傳圖片
上傳圖片
app.post('/add', function (req, res, next) {
var person = new Person({
image: './public/images/' + req.files.person.image.name;
});
var tmp_path = req.files.person.image.path;
var target_path = './public/images/' + req.files.person.image.name;
fs.rename(tmp_path, target_path, function (err) {
if (err) {
return next(new Error(err));
}
fs.unlink(tmp_path, function (err) {
if (err) {
console.log(err);
}
person.save(function (err) {
if (err) {
return next(new Error(err.message));
}
res.redirect('/view/' + person._id);
});
});
});
});
人查看頁面
app.get('/view/:id', function (req, res, next) {
Person.findById(req.params.id, function (err, person) {
if (err) {
return next(new Error(err));
}
if (!person) {
return next(new Error('Invalid reference to person information'));
}
fs.readFile(person.image, 'binary', function (err, file) {
if (err) {
return next(new Error(err));
} else {
res.render(path + 'view', {
title: title,
person: person,
file: file
});
}
});
});
});
的
並在我的view.jade我用來顯示圖片
img(src='#{file}')
但它沒有顯示,有人請幫助我!
是這塊玉好模板引擎? – underscore 2013-04-29 16:36:51
我對玉有很好的效果,也是我最常用的。有些人不喜歡的語法,但對我來說這是好的 – Noah 2013-04-29 16:38:47
謝謝Noah.one更多?使用直接html會更快嗎? – underscore 2013-04-29 16:40:00