You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The request streams are first written to temporary files using `os.tmpdir()`. File read streams associated with the temporary files are returned from the call to async-busboy. When the consumer has drained the file read streams, the files will be automatically removed, otherwise the host OS should take care of the cleaning process.
73
77
74
78
## Async API using custom onFile handler
79
+
75
80
If a custom onFile handler is specified in the options to async-busboy it
76
81
will only resolve an object containing fields, but instead no temporary files
77
82
needs to be created since the file stream is directly passed to the application.
@@ -80,22 +85,25 @@ to the implementation of busboy. If you don't care about a received
80
85
file stream, simply call `stream.resume()` to discard the content.
81
86
82
87
## Working with nested inputs and objects
88
+
83
89
Make sure to serialize objects before sending them as formData.
84
90
i.e:
85
-
```js
91
+
92
+
```json5
86
93
// Given an object that represent the form data:
87
94
{
88
-
'field1':'value',
89
-
'objectField': {
90
-
'key':'anotherValue'
95
+
field1:'value',
96
+
objectField: {
97
+
key:'anotherValue',
91
98
},
92
-
'arrayField': ['a', 'b']
99
+
arrayField: ['a', 'b'],
93
100
//...
94
-
};
101
+
}
95
102
```
96
103
97
104
Should be sent as:
98
-
```
105
+
106
+
```js
99
107
// -> field1[value]
100
108
// -> objectField[key][anotherKey]
101
109
// -> arrayField[0]['a']
@@ -104,22 +112,27 @@ Should be sent as:
104
112
```
105
113
106
114
Here is a function that can take care of this process
If you want to run some test locally, clone this repo, then run: `node examples/index.js`
138
151
From there you can use something like [Postman](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en) to send `POST` request to `localhost:8080`.
139
-
Note: When using Postman make sure to not send a `Content-Type` header, if it's filed by default, just delete it. (This is to let the `boudary` header be generated automaticaly)
140
-
152
+
Note: When using Postman make sure to not send a `Content-Type` header, if it's filed by default, just delete it. (This is to let the `boudary` header be generated automatically)
//This file is if you want to run some test localy, run: `node index.js`
2
-
//From there you can use something like [Postman](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en) to send `POST` request to `localhost:8080`.
3
-
//Note: When using Postman make sure to not send a `Content-Type` header, if it's field by default, juste delete it.
1
+
//This file is if you want to run some test locally, run: `node index.js`
2
+
//From there you can use something like [Postman](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en) to send `POST` request to `localhost:8080`.
3
+
//Note: When using Postman make sure to not send a `Content-Type` header, if it's field by default, juste delete it.
4
4
5
-
constasyncBusboy=require('../')
5
+
constasyncBusboy=require('../');
6
6
consthttp=require('http');
7
7
constPORT=8080;
8
8
9
-
functionhandleRequest(request,response){
10
-
asyncBusboy(request).then(function(formData){
11
-
// [You can put your tests here]
12
-
console.log('Files :',formData.files);
13
-
console.log('Fields :',formData.fields)
9
+
constserver=http
10
+
.createServer((req,res)=>{
11
+
if(req.method==='POST'){
12
+
console.log('POST request');
13
+
asyncBusboy(req).then(
14
+
function(formData){
15
+
// [You can put your tests here]
16
+
console.log('Files :',formData.files);
17
+
console.log('Fields :',formData.fields);
14
18
15
-
// We need to emit a reponse so that the request doesn't hang
16
-
response.end('It Works!! ');
17
-
},function(error){
18
-
console.log(error)
19
-
response.end('Something broke!! ');
19
+
// We need to emit a response so that the request doesn't hang
0 commit comments