Streaming an uploaded file to an HTTP request

时光总嘲笑我的痴心妄想 提交于 2019-12-08 15:17:32

I am not to familiar with the busboy module, but there errors you are getting are from attempting to use un-implemented streams. Whenever you create a new readable or writable stream directly from the stream module you have to create the _read and _write methods respectively Stream Implementors (node.js api). To give you something to work with the following example is using multer for handling multipart requests, I think you'll find multer is easier to use than busboy.

var app = require('express')();
var fs = require('fs');
var request = require('request');
app.use(multer());

app.post("/upload", function(req, res, next) {
    // create a 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 something to client
    })
});

I hope this helps unfortunately I am not familiar with busboy, but this should work with multer, and as I said before there problem is just that you are using un-implemented streams I'm sure there is a way to configure this operation with busboy if you wanted.

If you want to use multipart (another npm) here is a tutorial: http://qnimate.com/stream-file-uploads-to-storage-server-in-node-js/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!