@@ -184,6 +184,92 @@ form.submit({
184184});
185185```
186186
187+ ### Methods
188+
189+ #####_ void_ append( ** String** _ field_ , ** Mixed** _ value_ [ , ** Mixed** _ options_ ] )
190+ Append data to the form. You can submit about any format (string, integer, boolean, buffer, etc.). However, Arrays are not supported and need to be turned into strings by the user.
191+ ``` javascript
192+ var form = new FormData ();
193+ form .append ( ' my_string' , ' my value' );
194+ form .append ( ' my_integer' , 1 );
195+ form .append ( ' my_boolean' , true );
196+ form .append ( ' my_buffer' , new Buffer (10 ) );
197+ form .append ( ' my_array_as_json' , JSON .stringify ( [' bird' ,' cute' ] ) )
198+ ```
199+
200+ You may provide a string for options, or an object.
201+ ``` javascript
202+ // Set filename by providing a string for options
203+ form .append ( ' my_file' , fs .createReadStream (' /foo/bar.jpg' ), ' bar.jpg' );
204+
205+ // provide an object.
206+ form .append ( ' my_file' , fs .createReadStream (' /foo/bar.jpg' ), {filename: ' bar.jpg' , filesize: 1045 } );
207+ ```
208+
209+ #####_ Array_ getHeaders( [ ** Array** _ userHeaders_ ] )
210+ This method ads the correct ` content-type ` header to the provided array of ` userHeaders ` .
211+
212+ #####_ String_ getBoundary()
213+ Return the boundary of the formData. A boundary consists of 26x ` - ` followed by 24 numbers
214+ for example:
215+ ``` javascript
216+ -------------------------- 515890814546601021194782
217+ ```
218+ _ Note: The boundary must be unique and may not appear in the data._
219+
220+ #####_ Buffer_ getBuffer()
221+ Return the full formdata request package, as a Buffer. You can insert this Buffer in e.g. Axios to send multipart data.
222+
223+ ``` javascript
224+ var form = new FormData ();
225+ form .append ( ' my_buffer' , Buffer .from ([0x4a ,0x42 ,0x20 ,0x52 ,0x6f ,0x63 ,0x6b ,0x73 ]) );
226+ form .append ( ' my_file' , fs .createReadStream (' /foo/bar.jpg' ) );
227+
228+ axios .post ( ' https://example.com/path/to/api' ,
229+ form .getBuffer (),
230+ form .getHeaders ()
231+ )
232+ ```
233+
234+ #####_ Integer_ getLengthSync()
235+ Same as ` getLength ` but synchronous.
236+
237+ _ Note: getLengthSync __ doesn't__ calculate streams length._
238+
239+ #####_ Integer_ getLength( function _ callback_ )
240+ Returns the ` Content-Length ` async. The callback is used to handle errors and continue once the length has been calculated
241+ ``` javascript
242+ this .getLength (function (err , length ) {
243+ if (err) {
244+ this ._error (err);
245+ return ;
246+ }
247+
248+ // add content length
249+ request .setHeader (' Content-Length' , length);
250+
251+ ...
252+ }.bind (this ));
253+ ```
254+
255+ #####_ boolean_ hasKnownLength()
256+ Checks if the length of added values is known.
257+
258+ #####_ request_ submit( _ params_ , function _ callback_ )
259+ Submit the form to a web application.
260+ ``` javascript
261+ var form = new FormData ();
262+ form .append ( ' my_string' , ' Hello World' );
263+
264+ form .submit ( ' http://example.com/' , function (err , res ) {
265+ // res – response object (http.IncomingMessage) //
266+ res .resume ();
267+ } );
268+ ```
269+
270+ #####_ String_ toString()
271+ Returns the form data as a string. Don't use this if you are sending files or buffers, use ` getBuffer() ` instead.
272+
187273### Integration with other libraries
188274
189275#### Request
0 commit comments