javascript - Is it possible to forward a stream from one function to another? -


Please take a look at the following sample code.

As you can see, it uses parsing to write incoming form data and incoming files on disk. Let's say that these are just image files because my sample code uses imgur.com. (Does not require sending a content length header) uses the imgurUpload () function

Is it possible to extend additional image files, without having to buffer them to complete Need .com? (Use it on the ImgurUpload () function and within node-form-data?)

Server / Listener:

  var http = need ('http'), Basubi = ('Busboy'), formdata = is required ('form-data'), fs = 'required' ('fs') http.createServer (function (req, res) {if (req.method = ('File', 'file', function (field name, file, file name, encoding, mimetype) (Fs.createWriteStream ('1-' + filename)) // pipe the second time to file.pipe (fs.createWriteStream ('2-' + F) *) * * * How to connect things together? * Busby.on ('Res'writeHead' (200, {'connection': 'off'}) res.end ("full upload") }) Return to the Recovery (return) and if (req.method == = 'GET') {var stream = fs.createReadStream (__DERNAM + '/ index HTM') stream.pipe (res)}}) . Listen (80, function () {console.log ('listen to requests'}})   

HTML test form (index.html)

  & Lt ;! Doctype html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form Action = "/ Upload" method = "Post" Encrypt = "Multipart / Form-Data" & gt; & Lt; input type = "file" name = "file" & gt; & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  
  function imgurUpload (stream) {var form = new form data append ('filatata', FSCTRstream ('test.jpg')) form.append ('filatadet', / * How to connect things together? * / X) form.submit ('http://imgur.com/ upload', function (mistake, race) {if (mistake) disturbs var body = '' res .on ('data', function (piece) {body + = chunk}) res.on ('end', function () {console.log ('http://imgur.com/' + JSON.parse (body ) .data.hash)})})   

update (About mscdex reply)

  _stream_readable.js: 748 new error ('now' Can not be switched on Rane mode. "); ^ Error: can not switch to old mode anymore. EmitterDataEvents (_stream_readable.js: 748: 11) on the freestream function. Readable Pause (_stream_readable.js: 739: 3) function. On the DelayedStream.create (\ path \ node_modules \ form-data \ node_modules \ composite-stream \ node_modules \ FormData.append, formData.combinated stream.append (\ path \ node_modules \ form-data \ node_modules \ combined-stream \ lib \ Delay_stream.js: 45: 30) in delay-stream \ lib \ delayed_stream.js: 35: 12) (\ Path \ node_modules \ form-data \ lib \ form_data.js: 43: 3) imgurUpload (\ path \ app. js: 54: 8) on busboy. & Lt; Anonymous & gt; (\ Path \ app.js: 21: 4) & amp; nbsp; at basioimet (\ paths \ node_modules \ busboy \ lib \ main.js: 31: 35) in bisimet (events.js: 106: 17) in (Partistream); Anonymous & gt; (\ Path \ node_modules \ busboy \ lib \ types \ multipart.js: 205: 13)    

You can add readable streams as shown in the node-form-data redemption, then it:

  form.append ('filedate', stream );   

should work fine now.

Then in your file event handler:

  imgurUpload (file);    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -