我正在使用强大的来处理我在 NodeJs 中的文件上传。我有点卡在解析字段值上。
如何将 project_id 的值传递给表单处理程序,以便可以在文件名中写入参数?
<input type="text" id="project_id" value="{{projects._id}}" readonly>
编辑
更具体地说,这是我的表单上传处理的详细视图:
app.post('/uploads/', function (req, res){
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
res.writeHead(200, {'content-type': 'image/jpeg'});
res.write('received upload: \n\n');
var project = fields.project_id;
res.end(util.inspect(project, {fields: fields, files: files}));
});
form.on('end', function(project, fields, files){
console.log(project);
/*Temporary location of our uploaded file */
var temp_path = this.openedFiles[0].path;
/*The file name of the uploaded file */
var file_name = project + '.' + this.openedFiles[0].name;
我可以登录var project
该form.parse
部分。但我没有得到这form.on('end'...
部分的变量。
HTML 表单
<form id="uploadForm"
enctype="multipart/form-data"
action="/uploads/"
method="post">
<input type="text" name="project_id" id="project_id" value="{{projects._id}}" readonly>
<input multiple="multiple" type="file" name="upload" />
<button type="submit">Upload</button>
</form>