nodejs formidable

2016-01-20  本文已影响133人  wjing

node-formidable详解
博客园

express之前的版本包含formidable,之后的不包含。
下面介绍不包含的使用方法:

html

<form method="post" enctype="multipart/form-data"   action="/file-upload">
  <input type="file" name="thumbnail">
  <input type="submit">
</form>

server:

path是物理地址,不是相对项目根目录的相对地址
files.key: key是html中的name

router.post('/file-upload', function(req, res, next){

    var form = new formidable.IncomingForm();
    form.uploadDir = "../test/public/images";
    form.parse(req, function(err, fields, files) {
    //重命名
        fs.renameSync(files.thumbnail.path, "../test/public/images/"+files.thumbnail.name);
    });
});
上一篇 下一篇

猜你喜欢

热点阅读