Since the SmartStream class is just like any NodeJS readStream, you can throw a 'data' event handler on it.
You can then store the data.ContentLength value returned from the s3.headObject call and subtract the chunk length returned from the 'data' event. You can use this value to determine how much data is left, which you can then send to the frontend.
The neat thing about NodeJS streams is all of this can be done without editing the SmartStream class!
Thanks for reading and let me know if I can help any more!
sure, but how would you send this information to a client browser, using websockets?, I'm trying to use fetch streams for its simplicity but they don't work very well for me.
You can pipe this stream into the response from a http request. I found this article in a quick search that might help. Anywhere you see a fs.createReadStream you can substitute in this readStream!
There are numerous ways, including websockets, that this can be done. I would have to put in more research. If this article gets enough traction I could do a part 2 where I send the data to a frontend.
I ended up making an extremely simple front end, not sure if it will help in your case, but it might be a good starting point. You can fork it from my github if you like.
Thanks for sharing, what would be the best way to send the transfer progress percentage to the browser client?
Thank you for the question!
Since the SmartStream class is just like any NodeJS readStream, you can throw a 'data' event handler on it.
You can then store the
data.ContentLengthvalue returned from thes3.headObjectcall and subtract the chunk length returned from the 'data' event. You can use this value to determine how much data is left, which you can then send to the frontend.The neat thing about NodeJS streams is all of this can be done without editing the SmartStream class!
Thanks for reading and let me know if I can help any more!
sure, but how would you send this information to a client browser, using websockets?, I'm trying to use fetch streams for its simplicity but they don't work very well for me.
fetch-upload-streaming
You can pipe this stream into the response from a http request. I found this article in a quick search that might help. Anywhere you see a
fs.createReadStreamyou can substitute in this readStream!There are numerous ways, including websockets, that this can be done. I would have to put in more research. If this article gets enough traction I could do a part 2 where I send the data to a frontend.
I ended up making an extremely simple front end, not sure if it will help in your case, but it might be a good starting point. You can fork it from my github if you like.
github.com/about14sheep/awsstreaming