File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,3 +75,41 @@ request.post('https://up.flickr.com/services/upload', {
7575 // assert.equal(typeof body, 'object')
7676})
7777```
78+
79+ # Streams
80+
81+ ## ` POST ` data
82+
83+ Use Request as a Writable stream to easily ` POST ` Readable streams (like files, other HTTP requests, or otherwise).
84+
85+ TL;DR: Pipe a Readable Stream onto Request via:
86+
87+ ```
88+ READABLE.pipe(request.post(URL));
89+ ```
90+
91+ A more detailed example:
92+
93+ ``` js
94+ var fs = require (' fs' )
95+ , path = require (' path' )
96+ , http = require (' http' )
97+ , request = require (' request' )
98+ , TMP_FILE_PATH = path .join (path .sep , ' tmp' , ' foo' )
99+ ;
100+
101+ // write a temporary file:
102+ fs .writeFileSync (TMP_FILE_PATH , ' foo bar baz quk\n ' );
103+
104+ http .createServer (function (req , res ) {
105+ console .log (' the server is receiving data!\n ' );
106+ req
107+ .on (' end' , res .end .bind (res))
108+ .pipe (process .stdout )
109+ ;
110+ }).listen (3000 ).unref ();
111+
112+ fs .createReadStream (TMP_FILE_PATH )
113+ .pipe (request .post (' http://127.0.0.1:3000' ))
114+ ;
115+ ```
You can’t perform that action at this time.
0 commit comments