4

I am using the Busboy to upload the form data which contains the file and some text fields.

Every thing is working fine i am able to get the post parameters and file.

How can i achieve this: First I need to process the fields data and save in Db and process the file and update in same record in DB.

The busboy is first process the file and then process the fields.

req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
    console.log("Uploading: " + filename);
    console.log("fieldname: "+fieldname);
});
req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
    var jsondata = JSON.parse(val);
});

Any suggestions

4

2 回答 2

6

很简单:只需将您的字段放在表单中的文件之前。例子:

<form>
  <input type="text" name="foo">
  <input type="text" name="bar">
  <input type="file" name="baz">
</form>
于 2015-01-06T15:25:22.287 回答
1

busboy 将按照我们附加 formData 的顺序读取数据

form.append('field',value);
form.appnd('file',file);
于 2020-09-20T11:02:33.957 回答