Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File uploads are very slow with large file sizes. #1132

Open
thanathip41 opened this issue Nov 2, 2024 · 0 comments
Open

File uploads are very slow with large file sizes. #1132

thanathip41 opened this issue Nov 2, 2024 · 0 comments

Comments

@thanathip41
Copy link

const uWS = require('uWebSockets.js');
const port = 9001;
const fs = require('fs');

uWS.App()
.post('/*', (res, req) => {
const header = req.getHeader('content-type');
let buffer = Buffer.from('');
res.onData((ab, isLast) => {
buffer = Buffer.concat([buffer, Buffer.from(ab)]);
if (isLast) {
for (const {name, filename, data} of uWS.getParts(buffer, header)) {
if (name === 'file' && filename) {
fs.writeFileSync(filename, Buffer.from(data));
}
}
res.end('Thanks for the data!');
}
});

res.onAborted(() => {
console.log('Eh, okay. Thanks for nothing!');
});

}).listen(port, (token) => {
if (token) {
console.log('Listening to port ' + port);
} else {
console.log('Failed to listen to port ' + port);
}
});

I'm using example code to write a file, but it takes a long time to complete. How can I fix this?

I'm using a file that is around 700 MB, and it takes about 3 minutes to upload.
** I tested the file upload with http + busboy, and it takes about 11 seconds for the same 700 MB file.

Thank you!

@uNetworking uNetworking deleted a comment from youfeed Nov 10, 2024
@thanathip41 thanathip41 changed the title The file upload is very slow when the file size is large. File uploads are very slow with large file sizes. Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant