1

I would like to create file uploading app to box storage. I use box-sdk module to upload box. The box-sdk can access a file stream that is came from fs.createReadStream for uploading. I use multer module to access uploaded file. The multer module has memorystorage to store files. It produces a buffer string.

For uploading box, I have to convert buffer string to file stream. How can I convert it?

zanhtet
  • 2,040
  • 7
  • 33
  • 58

1 Answers1

1

You can just create a readable-stream and push your buffer into it.

var stream = require('stream')
var bufStream = stream.Readable()
bufStream._read = function () {}
bufStream.push(myBuffer)
bufStream.push(null)
bufStream.pause()

You can then pipe bufStream wherever you need to pipe it.

You can also use several, various modules to handle this for you

tkone
  • 22,092
  • 5
  • 54
  • 78