node.js - NodeJS - How to create fs.ReadStream object manually instead of fs.createReadStream? -


my app receiving stream via socket.io-stream , want use "fs.createreadstream" object (which returns fs.readstream object per node doc).

i want upload files box.com (obviously incoming stream content) using "box-node-sdk" requires "stream" object , works "fs.createreadstream". cannot directly pipe incoming stream , rather have convert "fs.createreadstream" object in order make use box api.

for eg: instead of fs.createreadstream('path/to/file'); //returns readstream object

how create? myreadstream(stream);

or how create? fs.createreadstream(stream);

could please me?

ss(socket).on('file', (stream, data) => {                      var streamfilename = './uploads/'+data.originalname;  		var streamdatasize = data.size;             		//method 1 - using incoming stream directly:  		//cannot use stream directly. not working. no error shown given box sdk.  		client.files.uploadfile('36155801746', data.originalname, stream, (err) => {    		  if (err) {  			//done(err);  		  } else {  			//done(null, {message: 'uploading finished'});  			console.log('upload box finished');  		  }    		});  		  	  		//alternative method 2 - save incoming stream file , again read file. doesn't work either. fails larger file size on 10 mb. settimeout 3 seconds , "boxstream" produced data 3 seconds of incoming stream.  		  		stream.pipe(fs.createwritestream(streamfilename);  		  		//read file again after few seconds because data being written incoming steram  		settimeout(() => {  		            var boxstream = fs.createreadstream(streamfilename);            client.files.uploadfile('36155801746', data.originalname, boxstream, (err) => {                  if (err) {                  //done(err);                } else {                  //done(null, {message: 'uploading finished'});                  console.log('upload box finished');                }                });          }, 3000);  		              });

streams streams; there's nothing special type returned fs.createreadstream, , box-node-sdk works type of stream.

this should work:

socketstream(socket).on('my-file', function (stream, data) {   boxclient.files.uploadfile(parentfolderid, data.name, stream, donecallback); }) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -