Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.io-stream question #16

Open
creativesoumik opened this issue Sep 8, 2017 · 1 comment
Open

socket.io-stream question #16

creativesoumik opened this issue Sep 8, 2017 · 1 comment

Comments

@creativesoumik
Copy link

creativesoumik commented Sep 8, 2017

My app receives a stream socket.io-stream which is emitted at browser and writes to a file using fs. Stream content is binary. But instead of writing to file I want to upload to box.com via their sdk which requires a readstream.

I have tried to use the socket stream directly to sdk upload method but it fail. The sdk upload method only works with fs.createReadStream method.

I need to know with the duplexify pack whether I can create a duplex stream which reads from socket io stream and outputs to box upload sdk?

Thanks

@creativesoumik
Copy link
Author

creativesoumik commented Sep 8, 2017

Here is my code so far

io.on('connection', socket => {
console.log('connection');
socket.emit('connected', 'hello World');
var uploadRunning = false;

ss(socket).on('file', (stream, data) => {
console.log('>>>Received File Emit at <<<', new Date().toString());
console.log('data.originalName', data.originalName);

var streamFileName = Date.now() + '.txt';

//saving to stream to file 
// stream.pipe(fs.createWriteStream( streamFileName ));

// I don't want rather use the "stream" down below in the uploadFile function
// var stream = fs.createReadStream('/path/to/file'); works but the above incoming stream doesn't

boxApiClient.files.uploadFile('36155801746', data.originalName, stream, (err) => {

  if (err) {} else {
    console.log('Upload to box finished');
  }

});

});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant