首页 > 代码库 > node+express4实现简单文件上传

node+express4实现简单文件上传

 

var express = require(‘express‘);                                                                                                                      var multiparty = require(‘multiparty‘);var app = express(); /*文件上传*/app.post(‘/uploadimg‘, function(req, res, next){    //生成multiparty对象,并配置上传目标路径    var form = new multiparty.Form({uploadDir: ‘./uploads‘});    //上传完成后处理    form.parse(req, function(err, fields, files){        console.log(fields);        var data =http://www.mamicode.com/ files;
     res.on(‘data‘, function(err, req, res, next){
        data = http://www.mamicode.com/files;
     }); res.send(data); });});app.listen(
3000,function(){ console.log("start:http://localhost:3000/uploadimg")})

 

node+express4实现简单文件上传