Skip to content

Commit 5d4dc40

Browse files
committed
docs: better readme
1 parent 459e5bf commit 5d4dc40

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ See it's defaults in [src/Formidable.js DEFAULT_OPTIONS](./src/Formidable.js)
331331
- `options.maxFieldsSize` **{number}** - default `20 * 1024 * 1024` (20mb);
332332
limit the amount of memory all fields together (except files) can allocate in
333333
bytes.
334-
- `options.hash` **{boolean}** - default `false`; include checksums calculated
334+
- `options.hash` **{string | false}** - default `false`; include checksums calculated
335335
for incoming files, set this to some hash algorithm, see
336336
[crypto.createHash](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options)
337337
for available algorithms
@@ -431,12 +431,12 @@ later.
431431
```js
432432
form.once('error', console.error);
433433

434-
form.on('fileBegin', (filename, file) => {
435-
form.emit('data', { name: 'fileBegin', filename, value: file });
434+
form.on('fileBegin', (formname, file) => {
435+
form.emit('data', { name: 'fileBegin', formname, value: file });
436436
});
437437

438-
form.on('file', (filename, file) => {
439-
form.emit('data', { name: 'file', key: filename, value: file });
438+
form.on('file', (formname, file) => {
439+
form.emit('data', { name: 'file', formname, value: file });
440440
});
441441

442442
form.on('field', (fieldName, fieldValue) => {
@@ -448,7 +448,7 @@ form.once('end', () => {
448448
});
449449

450450
// If you want to customize whatever you want...
451-
form.on('data', ({ name, key, value, buffer, start, end, ...more }) => {
451+
form.on('data', ({ name, key, value, buffer, start, end, formname, ...more }) => {
452452
if (name === 'partBegin') {
453453
}
454454
if (name === 'partData') {
@@ -466,10 +466,10 @@ form.on('data', ({ name, key, value, buffer, start, end, ...more }) => {
466466
console.log('field value:', value);
467467
}
468468
if (name === 'file') {
469-
console.log('file:', key, value);
469+
console.log('file:', formname, value);
470470
}
471471
if (name === 'fileBegin') {
472-
console.log('fileBegin:', key, value);
472+
console.log('fileBegin:', formname, value);
473473
}
474474
});
475475
```
@@ -628,7 +628,13 @@ you want to stream the file to somewhere else while buffering the upload on the
628628
file system.
629629

630630
```js
631-
form.on('fileBegin', (name, file) => {});
631+
form.on('fileBegin', (formName, file) => {
632+
// accessible here
633+
// formName the name in the form (<input name="thisname" type="file">)
634+
// file.name (http filename)
635+
// file.path default pathnme as per options.uploadDir and options.filename
636+
// file.path = CUSTOM_PATH // to change the final path
637+
});
632638
```
633639

634640
#### `'file'`
@@ -637,7 +643,11 @@ Emitted whenever a field / file pair has been received. `file` is an instance of
637643
`File`.
638644

639645
```js
640-
form.on('file', (name, file) => {});
646+
form.on('file', (formname, file) => {
647+
// same as fileBegin, except
648+
// it is too late to change file.path
649+
// file.hash is available if options.hash was used
650+
});
641651
```
642652

643653
#### `'error'`

0 commit comments

Comments
 (0)