Throttle (pause/resume) file upload #1043
-
...Synchronicity for unique file names is killing me. I'm having a hard time, with the not being able to perform any async operation before: res.onData while receiving a post. I'm setting up a file upload server, and I need to get a unique filename for my stream in an async way, there's just too much concurrency to do it any other way, is this really not feasible? :( If I perform an async operation to get fileName, then res.onData just won't perform its callback, like there's nothing there.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can pause receiving with https://unetworking.github.io/uWebSockets.js/generated/interfaces/HttpResponse.html#pause.pause-1 But you need to buffer up spurious data either way (up to 512kb but for correctness you need to handle all spurious data). So call onData first, then call pause and when you have your filename call resume then write first your buffered up then from onData. This library does not hide or fake behavior that would be non-technical so for this reason there still is spurious data like mentioned above (it's impossible to know, efficiently) |
Beta Was this translation helpful? Give feedback.
-
Gotcha, thanks. |
Beta Was this translation helpful? Give feedback.
You can pause receiving with https://unetworking.github.io/uWebSockets.js/generated/interfaces/HttpResponse.html#pause.pause-1
But you need to buffer up spurious data either way (up to 512kb but for correctness you need to handle all spurious data). So call onData first, then call pause and when you have your filename call resume then write first your buffered up then from onData.
This library does not hide or fake behavior that would be non-technical so for this reason there still is spurious data like mentioned above (it's impossible to know, efficiently)