html+form+multipartform-data,表单 – 如何处理node.js中的multipart / form-data
以下鏈接重復提問.
這是一個例子:
// Expose modules in ./support for demo purposes
require.paths.unshift(__dirname + '/../../support');
/**
* Module dependencies.
*/
var express = require('../../lib/express')
, form = require('connect-form');
var app = express.createServer(
// connect-form (http://github.com/visionmedia/connect-form)
// middleware uses the formidable middleware to parse urlencoded
// and multipart form data
form({ keepExtensions: true })
);
app.get('/', function(req, res){
res.send('
'+ '
Image:
'+ '
+ '
');});
app.post('/', function(req, res, next){
// connect-form adds the req.form object
// we can (optionally) define onComplete, passing
// the exception (if any) fields parsed, and files parsed
req.form.complete(function(err, fields, files){
if (err) {
next(err);
} else {
console.log('\nuploaded %s to %s'
, files.image.filename
, files.image.path);
res.redirect('back');
}
});
// We can add listeners for several form
// events such as "progress"
req.form.on('progress', function(bytesReceived, bytesExpected){
var percent = (bytesReceived / bytesExpected * 100) | 0;
process.stdout.write('Uploading: %' + percent + '\r');
});
});
app.listen(3000);
console.log('Express app started on port 3000');
如果您的問題沒有解決,請訪問this link.這是一篇關于文件上傳的好文章.
總結
以上是生活随笔為你收集整理的html+form+multipartform-data,表单 – 如何处理node.js中的multipart / form-data的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html 重复提交表单,表单重复提交问题
- 下一篇: 上海教师中级职称英语计算机考试,计算机教