You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
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!
The text was updated successfully, but these errors were encountered: