node.js - Streaming an uploaded file to an HTTP request -


my goal accept uploaded file , stream wistia using the wistia upload api. need able add fields http request, , don't want file touch disk. i'm using node, express, request, , busboy.

the code below has 2 console.log statements. first returns [error: not implemented] , second returns [error: form-data: not implemented]. i'm new streaming in node, i'm doing fundamentally wrong. appreciated.

app.use("/upload", function(req, res, next) {     var writestream = new stream.writable();     writestream.on("error", function(error) {         console.log(error);     });     var busboy = new busboy({headers: req.headers});     busboy.on("file", function(fieldname, file, filename, encoding, mimetype) {         file.on("data", function(data) {             writestream.write(data);         });         file.on("end", function() {             request.post({                 url: "https://upload.wistia.com",                 formdata: {                     api_password: "abc123",                     file: new stream.readable(writestream)                 }             }, function(error, response, body) {                 console.log(error);             });         });     });     req.pipe(busboy); }); 

i not familiar busboy module, there errors getting attempting use un-implemented streams. whenever create new readable or writable stream directly stream module have create _read , _write methods respectively stream implementors (node.js api). give work following example using multer handling multipart requests, think you'll find multer easier use busboy.

var app = require('express')(); var fs = require('fs'); var request = require('request'); app.use(multer());  app.post("/upload", function(req, res, next) {     // create read stream     var readable = fs.createreadstream(req.files.myfile.path);     request.post({         url: "https://upload.wistia.com",         formdata: {             api_password: "abc123",             file: readable         }         }, function(err, res, body) {         // send client     }) }); 

i hope helps unfortunately not familiar busboy, should work multer, , said before there problem using un-implemented streams i'm sure there way configure operation busboy if wanted.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -