Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note how to defer file descriptor creation/use a stream Ctor #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', new Buffer(10));
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
var streamCtor = (next) => next(fs.createReadStream('/foo/bar.jpg'));
streamCtor.path = '/foo/bar.jpg'
form.append('my_deferred_file', streamCtor)
```

Also you can use http-response stream:
Expand Down Expand Up @@ -216,6 +219,15 @@ form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), 'bar.jpg' );
form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), {filename: 'bar.jpg', contentType: 'image/jpeg', knownLength: 19806} );
```

If you need to upload many files and want to defer the creation of a file descriptor until read time, you can pass in a function with the [`next` callback as the first argument](https://github.com/felixge/node-combined-stream#usage). The function must have the `path` property of the fs.createReadStream, however.

```js
var streamCtor = (next) => next(fs.createReadStream('/foo/bar.jpg'));
streamCtor.path = '/foo/bar.jpg'

form.append('my_deferred_file', streamCtor)
```

#### _Headers_ getHeaders( [**Headers** _userHeaders_] )
This method adds the correct `content-type` header to the provided array of `userHeaders`.

Expand Down