Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I process the fields first and then process the files in Nodejs busboy

Tags:

node.js

busboy

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

like image 283
Vivek G.S Avatar asked Mar 18 '23 10:03

Vivek G.S


1 Answers

Simple: just put your fields before your files in your form. Example:

<form>
  <input type="text" name="foo">
  <input type="text" name="bar">
  <input type="file" name="baz">
</form>
like image 197
mscdex Avatar answered Mar 19 '23 22:03

mscdex