uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.86k stars 569 forks source link

Add file upload example #867

Closed krm35 closed 9 months ago

uNetworkingAB commented 1 year ago

const {fileName} = querystring.parse(req.getQuery());

We have res.getQuery("filename") and we also have MultipartParser built-in.

krm35 commented 1 year ago

yep I use it but forgot to implement it https://github.com/uNetworking/uWebSockets.js/issues/529#issuecomment-851046029

IonelLupu commented 10 months ago

@krm35 @uNetworkingAB I debugged big file upload for hours and I noticed you have to copy the chunk, the write it on disk (or whatever stream).

For example, this .slice(0) from this line writeStream.write(Buffer.from(chunk.slice(0))); is super important. Otherwise, it won't write anything to the stream.

What is the explanation?

krm35 commented 10 months ago

Needs to slice to make a deep copy of the chunk otherwise there is a reference problem

uNetworkingAB commented 10 months ago

It's always a good idea to read the documentation https://unetworking.github.io/uWebSockets.js/generated/interfaces/HttpResponse.html#onData