Skip to content

Commit

Permalink
add some exposition to mpu example in README.md
Browse files Browse the repository at this point in the history
This is re @mikeal's comment here:
#345 (comment)

This updates the mpu example in the README with some more comments and a callback to make the usage unmistakably clear for beginners and especially forgetful developers (e.g. @mikermcneil)
  • Loading branch information
mikermcneil committed Feb 12, 2014
1 parent e2a14cc commit 1efea37
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,20 @@ request.post('http://service.com/upload').form({key:'value'})
For `multipart/form-data` we use the [form-data](https://github.com/felixge/node-form-data) library by [@felixge](https://github.com/felixge). You don’t need to worry about piping the form object or setting the headers, `request` will handle that for you.

```javascript
var r = request.post('http://service.com/upload')
var r = request.post('http://service.com/upload', function optionalCallback (err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
})
var form = r.form()
form.append('my_field', 'my_value')
form.append('my_buffer', new Buffer([1, 2, 3]))
form.append('my_file', fs.createReadStream(path.join(__dirname, 'doodle.png'))
form.append('remote_file', request('http://google.com/doodle.png'))

// Just like always, `r` is a writable stream, and can be used as such (you have until nextTick to pipe it, etc.)
// Alternatively, you can use the callback (that's what this example does-- see `optionalCallback` above).
```
## HTTP Authentication
Expand Down

0 comments on commit 1efea37

Please sign in to comment.