之前我發佈我的問題,你必須現在,我是新的使用node.js.我如何顯示最終上傳的圖像與視圖玉
因此,我使用express,fs和easyimage來構建圖像上傳器,它的工作正常。我想使用jade在客戶端(視圖)中顯示最終調整大小的動態圖像。
這是我的路線images.js文件:
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res) {
res.send('home');
});
router.get('/upload', function(req, res) {
res.sendfile("./public/html/images-upload.html");
});
router.post('/upload', function(req, res) {
var multiparty = require("multiparty");
var form = new multiparty.Form();
form.parse(req, function(err,fields,files){
var img = files.images[0];
var fs = require("fs");
var easyimg = require("easyimage");
fs.readFile(img.path, function(err, data){
var path = "./public/images/"+img.originalFilename;
easyimg.rescrop({
src:"public/images/"+img.originalFilename, dst:"public/uploads/"+img.originalFilename,
width:150, height:150,
cropwidth:128, cropheight:128,
x:0, y:0
}).then(
function(image) {
console.log('Resized and cropped: ' + image.width + 'image.height);
},
function (err) {
console.log(err);
});
fs.writeFile(path, data, function(error) {
if(error) console.log(error);
//controller
var jade = require('jade');
res.render('home', {templateRender: jade.renderFile})
//template
});
});
});
});
module.exports = router;
很多感謝提前! –