#Saving a file through HTTP async
35 messages · Page 1 of 1 (latest)
you could use @Response() res
then res.end() to reply while running writeFile
And how your controller’s method looks like?
Don’t forget the await in the promise of writeFile after calling res.end()
Why I should add 'await'? 🙂
Do you want to make sure it fully writes to the disk without error before sending the response or do you want to have a floating promise?
Floating promise for now
do you have any idea? @robust eagle
What you have now shouldn't block the request
You mean this?
Yes. You probably don't actually need the res.end. the server should respond even if there's a floating promise
Just don't add the @Res() to the controller and nest should take care of sending a response for you
Yeah. But even though when I upload a file (I'm testing a large one) the response from server waits for a file to be uploaded. That's my controller and I start using yarn run:start
What do you mean here by "uploaded"? Do you mean saved to the disk, or just sent to the server?
saved to the disk
Do you have a multer module being used?
I think so? I added the @types/multer
and take a file as Express.Multer.File
No, like, MulterModule.register()
Hmm I havent used that
Okay, making sure. So it shouldn't be waiting to be written to disk to serve the response
Does it still wait even if your remove the @Response()?
Yes, thats my code:
Yeah, it shouldn't Wait to respond. Can you make a git repo with this? Unless multer is forcing the wait this should be responding immediately
Could you not have sent it publicly?
I mean it's kinda private repo
I'm not the only person who looks at this stuff/not the only one capable of investigating
Then make a reproduction that is public
OK 
I think I've found a "why" to my problem while I was doing a reproduction @robust eagle 🤣 The delay was not on the server side - but on the client. Just sending through network that file was very long and the writeFile was right away after it went through
Writing to disk is way faster then sending over an http request. That's why I was asking if you were certain it was waiting for the write to finish 😁