node 上传文件
发布日期:2021-08-31 01:31:41 浏览次数:9 分类:技术文章

本文共 958 字,大约阅读时间需要 3 分钟。

hot3.png

file.js文件

需要安装formidable 模块

var formidable = require('formidable');var     http = require('http');var     sys = require('sys');  http.createServer(function(req, res) {       if (req.url == '/upload' && req.method.toLowerCase() == 'post') {     // parse a file upload         var form = new formidable.IncomingForm();         form.parse(req, function(err, fields, files) {               res.writeHead(200, {'content-type': 'text/plain; charset=UTF-8'});            res.write('received upload:\n\n');               res.end(sys.inspect({err:err, fields: fields, files: files}));         });         return;   }     // show a file upload form    res.writeHead(200, {'content-type': 'text/html; charset=UTF-8'});   res.end(         ''+    '
'+    'What is your name? 
'+    'What files are you sending? 
'+    '
'+    ''   ); }).listen(8888);console.log("Server has started.");

转载于:https://my.oschina.net/shunshun/blog/299201

转载地址:https://blog.csdn.net/weixin_34056162/article/details/91968190 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Oracle中组合索引的使用详解
下一篇:数据库设原则

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月16日 09时33分27秒