简体   繁体   English

我如何在node.js中获得“名称”属性

[英]How can I get the “name” attribute in node.js

<input type='file' name='upload1'/>

When this form is submitted,how can I get the "name" attribute (upload1) on node.js. 提交此表单后,如何在node.js上获取“名称”属性(upload1)。 I use restify,and upload image. 我使用restify,并上传图片。

只需将node-formidable用于文件上传。

The right way in node.js is would be to use a web app framework like express. 在node.js中,正确的方法是使用网络应用程序框架(例如express)。 It gives you more options as well as flexibility. 它为您提供更多选择和灵活性。 In express you can do : 快递您可以:

var express = require('express');                     //Initialize express
var app = express();
app.listen(3000);

app.use(express.bodyParser());                        //to parse the forms
app.post('/pagesubmit', function(request, response){  //to handle POST to the page
  console.log(request.body.username);                 //tp access input text 'username'
  console.log(request.files.name);                    //to access input file 'name'
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM