Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

post上传数据显示链接已重置怎么解决

$
0
0

我想使用formidable上传表单里的博客信息,其中图片上传到硬盘,其他信息传进数据库。代码如下,但是每次都显示连接已重置,blogMoudle.publish里的代码根本执行不到,请问为什么啊?我该怎么办? router.post(’/publish’, (req, res, next) => {

var form = new formidable.IncomingForm();   //创建上传表单

form.encoding = 'utf-8';		//设置编辑
form.uploadDir = './public/images/blog/';	 //设置上传目录
form.keepExtensions = true;	 //保留后缀
form.maxFieldsSize = 2 * 1024 * 1024;   //文件大小

form.parse(req, function (err, fields, files) {

    var avatarName = Date.now() + '.png';
    var newPath = form.uploadDir + avatarName;
    var blog = fields;
    var url = './public/images/blog/' + avatarName;

    fs.renameSync(files.pic_url.path, newPath);  //重命名

    blog.author = 'HKH';
    blog.read_quality = 0;
    blog.good_amount = 0;
    blog.comment_amount = 0;
    blog.pic_url = url || '/public/images/u2091.jpg';

    blogModule.publish(blog, () => {
        console.log('hello');
        res.render('index', {title: 'HKH博客'})
    });
});
});

2017-02-03_003341.jpg


Viewing all articles
Browse latest Browse all 14821

Trending Articles