#Saving a file through HTTP async

35 messages · Page 1 of 1 (latest)

edgy birch
#

Hi,

I'm trying to save the file without blocking the HTTP request.
Is this possible?

eager moat
#

you could use @Response() res
then res.end() to reply while running writeFile

edgy birch
#

in a controller?

#

did something like this, but still

eager moat
#

And how your controller’s method looks like?

eager moat
edgy birch
robust eagle
edgy birch
#

Floating promise for now

edgy birch
#

do you have any idea? @robust eagle

robust eagle
#

What you have now shouldn't block the request

edgy birch
robust eagle
#

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

edgy birch
#

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

robust eagle
#

What do you mean here by "uploaded"? Do you mean saved to the disk, or just sent to the server?

edgy birch
#

saved to the disk

robust eagle
#

Do you have a multer module being used?

edgy birch
#

I think so? I added the @types/multer
and take a file as Express.Multer.File

robust eagle
#

No, like, MulterModule.register()

edgy birch
#

Hmm I havent used that

robust eagle
#

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()?

edgy birch
#

Yes, thats my code:

robust eagle
#

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?

edgy birch
#

I mean it's kinda private repo

robust eagle
#

I'm not the only person who looks at this stuff/not the only one capable of investigating

robust eagle
edgy birch
#

OK despairge

edgy birch
#

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

robust eagle
#

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 😁

edgy birch
#

yeah sorry I thought the other way 😄 because I was always getting the response as soon as the file was on the storage on the server so I was confused 😄

#

anyway thanks